https://www.acmicpc.net/problem/10815
10815번: 숫자 카드
첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,
www.acmicpc.net
import sys
n = int(input())
cNum = list(map(int, sys.stdin.readline().split()))
m = int(input())
card = list(map(int, sys.stdin.readline().split()))
cNum = sorted(cNum)
answer = ''
for num in card:
lt = 0
rt = n - 1
flag = 0
while lt <= rt:
mid = (lt + rt) // 2
if cNum[mid] < num:
lt = mid +1
elif cNum[mid] == num:
flag = 1
break
else:
# cNum[lt] > num
rt = mid -1
answer += str(flag) + ' '
print(answer[:-1])
'코딩테스트 > 백준' 카테고리의 다른 글
[백준] 11053번 가장 긴 증가하는 부분수열 - dp, LIS (0) | 2022.09.14 |
---|---|
[백준] 12015번 가장 긴 증가하는 부분수열2 - 이분탐색, LIS (0) | 2022.09.14 |
[백준] 14888번 연산자 끼워넣기 - dfs, 백트래킹 (0) | 2022.09.12 |
[백준] 14889번 스타트와 링크 - dfs, 백트래킹 (0) | 2022.09.12 |
[백준] 2798번 블랙잭 - dfs, 백트래킹 (0) | 2022.09.11 |