Gidhub BE Developer

[BOJ] 2776. 암기왕

2018-09-26
goodGid

Problem

Problem URL : 암기왕


[1] Answer Code (18. 09. 26)

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    int tc;
    cin >> tc;
    while (tc--) {
        int n;
        cin >> n ;
     
        vector<int> v;
        for(int i=0; i<n; i++){
            int tmp;
            cin >> tmp;
            v.push_back(tmp);
        }
        sort(v.begin(), v.end());
        
        cin >> n;
        for(int i=0; i<n; i++){
            int tmp;
            cin >> tmp;
            if(binary_search(v.begin(),v.end(),tmp))
                cout << "1" << '\n';
            else
                cout << "0" << '\n';
        }
    }
    return 0;
}

Review

  • cout « endl; 로 하니까 시간 초과가 떴다.

  • endl -> \n 으로 바꾸니 해결 !


Recommend

Index