반응형
문제 링크
코드
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
unordered_set<int> s;
int n, m, t;
cin >> n;
while (n--) {
cin >> t;
s.insert(t);
}
cin >> m;
while (m--) {
cin >> t;
if (s.find(t) != s.end()) cout << 1 << '\n';
else cout << 0 << '\n';
}
}
설명
unordered_set은 Hash 구조이므로 find의 시간복잡도가 O(1)이다.
(주의) 기록용으로 작성한 글입니다. 좋은 코드가 아닐 수 있습니다.
댓글 환영합니다!
반응형
'Algorithm > BOJ' 카테고리의 다른 글
[백준/BOJ] 1934번 - 최소공배수 (C++) (0) | 2022.03.22 |
---|---|
[백준/BOJ] 2010번 - 플러그 (C++) (0) | 2022.03.22 |
[백준/BOJ] 1764번 - 듣보잡 (C++) (0) | 2022.03.22 |
[백준/BOJ] 1755번 - 숫자 놀이 (C++) (0) | 2022.03.22 |
[백준/BOJ] 1712번 - 손익분기점 (C++) (0) | 2022.03.21 |
댓글