Notice
Recent Posts
Recent Comments
Link
Little Jay
[C++] 백준 1931번 - 회의실 배정 본문
간단한 이진탐색 문제
참 메모리라는게 아속하다
문제의 태그에는 set 혹은 map이 달려있어서
처음에는 당연히 set으로 풀었는데
시간초과가 발생해버렸다.
아무래도 set이나 map이나 기능적으로 이진트리의 모습을 만들어야하기 때문에
계속해서 sort해주는 부분에서 메모리를 많이 잡아먹은 것 같다.
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n;
cin >> n;
vector<int> v;
for (int j = 0; j < n; j++) {
int temp;
cin >> temp;
v.push_back(temp);
}
sort(v.begin(), v.end());
int m;
cin >> m;
for (int j = 0; j < m; j++) {
int temp;
cin >> temp;
if (binary_search(v.begin(), v.end(), temp))
cout << 1 << "\n";
else
cout << 0 << "\n";
}
}
return 0;
}'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 11724번 - 연결 요소의 개수 (0) | 2021.08.19 |
|---|---|
| [C++] 백준 1260번 - DFS와 BFS (0) | 2021.08.19 |
| [C++] 백준 1406번 - 에디터 (0) | 2021.08.18 |
| [C++] 백준 4889번 - 안정적인 문자 (0) | 2021.08.17 |
| [C++] 백준 7568번 - 덩치 (0) | 2021.08.17 |
Comments