#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//https://www.acmicpc.net/problem/10815
bool MatchCards(int start, int end, int target, vector<int>& sanggeunCards) {
while (start <= end) {
int mid = (start + end) / 2;
if (sanggeunCards[mid] == target)
return true;
if (sanggeunCards[mid] < target)
start = mid + 1;
else
end = mid - 1;
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int n = 0, m = 0;
cin >> n;
vector<int> sanggeunCards(n);
for (int i = 0; i < n; ++i)
cin >> sanggeunCards[i];
sort(sanggeunCards.begin(), sanggeunCards.end());
int num = 0;
cin >> m;
for (int i = 0; i < m; ++i) {
cin >> num;
cout << MatchCards(0, n - 1, num, sanggeunCards) << " ";
}
return 0;
}
메모리 줄이려 애쓴 문제..
다른 분의 코드가 메모리를 줄이는 데에 도움이 많이 됐다
https://www.acmicpc.net/problem/10815
'알고리즘 공부' 카테고리의 다른 글
숫자 짝꿍 (0) | 2024.01.16 |
---|---|
프로그래머스 136798. 기사단원의 무기 (1) | 2023.12.27 |
백준 2805번 나무자르기 C++ (1) | 2023.10.10 |
백준 10866번 덱 C++ (1) | 2023.10.06 |
백준 10845번 큐 C++ (0) | 2023.10.06 |