ps:problems:boj:10816
숫자 카드 2
| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 10816 |
| 문제명 | 숫자 카드 2 |
| 레벨 | 실버 4 |
| 분류 |
기초 |
| 시간복잡도 | O(n+m) |
| 인풋사이즈 | n<=500,000, m<=500,000 |
| 사용한 언어 | Python |
| 제출기록 | 115084KB / 832ms |
| 최고기록 | 130124KB / 556ms |
| 해결날짜 | 2021/07/13 |
| 태그 | |
풀이
- 숫자 카드와 유사하나, 숫자의 존재 여부 대신, 숫자가 몇개 존재하는지를 찾는다
- Collections.Counter를 쓰면 간단하게 구현 가능하다. 시간복잡도는 O(n+m).
코드
"""Solution code for "BOJ 10816. 숫자 카드 2".
- Problem link: https://www.acmicpc.net/problem/10816
- Solution link: http://www.teferi.net/ps/problems/boj/10816
"""
import collections
def main():
N = int(input()) # pylint: disable=unused-variable
A = [int(x) for x in input().split()]
M = int(input()) # pylint: disable=unused-variable
nums = [int(x) for x in input().split()]
counter = collections.Counter(A)
print(*(counter[num] for num in nums))
if __name__ == '__main__':
main()
ps/problems/boj/10816.txt · 마지막으로 수정됨: 2021/07/19 15:33 저자 teferi

토론