Python/코딩테스트
[백준] 10815. 숫자 카드
edoyyoy
2023. 10. 9. 17:10
10815번: 숫자 카드
첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,
www.acmicpc.net
✓ 난이도 : 실버 5
✓ 문제 풀이 : 이분탐색
백준 1920. 수찾기와 유사한 문제
<이분탐색 사용>
import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
m = int(input())
chk = list(map(int, input().split()))
num.sort()
for c in chk:
s, e = 0, n-1
ans = 0
while s <= e:
mid = (s+e)//2
if num[mid] == c:
ans = 1
break
elif num[mid] < c:
s = mid+1
else:
e = mid -1
print(ans, end=' ')
<set 사용>
import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
m = int(input())
chk = list(map(int, input().split()))
num = set(num)
for c in chk:
if c in num:
print(1, end=' ')
else:
print(0, end=' ')