Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 구현
- 시뮬레이션
- 그래프 탐색
- DP
- 에라토스테네스의 체
- 우선순위큐
- 해시
- 수학
- 크루스칼
- 서브쿼리
- 재귀
- 분할정복
- MST
- 투포인터
- 다익스트라
- 그래프 이론
- 누적합
- 다이나믹 프로그래밍
- DFS
- join
- 브루트포스
- 그리디
- 트리
- 다시
- 자료구조
- 다이나믹프로그래밍
- GROUP BY
- BFS
- 플로이드-워셜
- 백트래킹
Archives
- Today
- Total
기록하고 까먹지 말기
10816 본문
날짜 : 2022. 9. 12
사용 언어 : python
문제
코드
import sys
n = int(sys.stdin.readline())
nums = list(map(int, sys.stdin.readline().split()))
m = int(sys.stdin.readline())
cards = list(map(int, sys.stdin.readline().split()))
cnt = dict()
for i in nums:
if i in cnt:
cnt[i] += 1
else:
cnt[i] = 1
for i in cards:
if i in cnt:
print(cnt[i], end=" ")
else:
print("0", end=" ")
알게된 점
- in 연산은 list, dict, set마다 시간복잡도가 상이하다.
- dict는 hash 방식을 사용하기 때문에 in 연산을 사용해도 리스트보다 시간복잡도가 좋게 나타난다.(O(1))
- 타입에 따라 시간복잡도를 고려해서 코드를 쉽게 짜는 것이 관건인듯
참고 사이트
- https://wiki.python.org/moin/TimeComplexity