728x90
< 해결 방법 >
pypy3 로 돌리니까 시간 초과가 안나왔다. 이분탐색이나 set 을 이용한 방법도 존재하고, set 에서의 in 검색의 시간복잡도는 O(1) 이라고 한다.
import sys
a = int(input())
n = list(map(int,sys.stdin.readline().rstrip().split(" ")))
b = int(input())
m = list(map(int,sys.stdin.readline().rstrip().split(" ")))
n = sorted(n)
for i in range(0,len(m)):
if m[i] in n:
print(1)
else:
print(0)
728x90
'🟢 알고리즘 문제 풀이 > Baekjoon' 카테고리의 다른 글
| [파이썬] 백준 2740 행렬 곱셈 (0) | 2022.10.01 |
|---|---|
| [파이썬] 백준 5430 AC (0) | 2022.10.01 |
| [파이썬] 백준 11866 요세푸스 문제 0 (0) | 2022.09.27 |
| [파이썬] 백준 10866 덱 (1) | 2022.09.22 |
| [파이썬] 백준 18258 큐2 (1) | 2022.09.22 |