Little Jay

[C++] 백준 1931번 - 회의실 배정 본문

알고리즘/BOJ

[C++] 백준 1931번 - 회의실 배정

Jay, Lee 2021. 8. 18. 11:59

간단한 이진탐색 문제

참 메모리라는게 아속하다

문제의 태그에는 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;
}
Comments