Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 오퍼레이팅시스템
- 너비우선탐색
- 코딩
- 컴공
- 스택
- DP
- cs
- Stack
- c++
- 북리뷰
- 컴퓨터공학과
- 알고리즘
- Computer science
- 구현
- 정석학술정보관
- bfs
- Operating System
- 오에스
- 백준
- 자료구조
- 그래프
- vector
- 코테
- 컴공과
- 개발
- 정석
- coding
- 브루트포스
- 문제풀이
- OS
Archives
- Today
- Total
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