이진 탐색 알고리즘
Q
10816번: 숫자 카드 2
첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,
www.acmicpc.net
A
이진 탐색 알고리즘을 해보니 시간초과가 떳다. 그냥 collections 모듈에 있는 Counter를 사용하여 풀었다.
코드
n = int(input())
array = list(map(int, input().split()))
m = int(input())
target_list = list(map(int, input().split()))
from collections import Counter
result = []
count1 = Counter(array)
for k in range(m):
result = count1[target_list[k]] #대괄호를 사용하여야 한다.
print(result, end = ' ')