10816번 - 숫자 카드 2
import sys
input = sys.stdin.readline
a = int(input())
b = list(map(int, input().split()))
c = int(input())
d = list(map(int, input().split()))
e = []
for i in d:
e.append(b.count(i))
f = ""
for i in range(c - 1):
f += str(e[i]) + " "
f += e[c - 1]
print(f)
딕셔너리에 특정 숫자의 개수를 담는 방식으로 로직을 구성해보세요. count를 사용하는 방법은 count의 시간복잡도가 O(N)이므로 제한 시간 내에 해결하지 못합니다.
댓글을 작성하려면 로그인해야 합니다.
smilingwon20 2년 전
import sys
input = sys.stdin.readline
a = int(input())
b = list(map(int, input().split()))
c = int(input())
d = list(map(int, input().split()))
e = []
for i in d:
e.append(b.count(i))
f = ""
for i in range(c - 1):
f += str(e[i]) + " "
f += e[c - 1]
print(f)