코테 준비/Hash map
-
[프로그래머스] 오픈채팅방코테 준비/Hash map 2024. 2. 2. 10:59
처음에는 노가다로 풀었는데 25번 테스트케이스부터 시간 초과가 났다... def solution(record): answer = [] id=[] for i in record: i=i.split(' ') if i[0]=='Enter': id.append(['Enter',i[1],i[2]]) for j in range(len(id)): if id[j][1]==i[1] and len(id[j])==3: id[j][2]=i[2] elif i[0]=='Leave': for j in range(len(id)): if id[j][1]==i[1]: id.append(['Leave',i[1],id[j][2]]) break elif i[0]=='Change': for j in range(len(id)): if id[j][..
-
[백준] 1269. 대칭 차집합코테 준비/Hash map 2023. 1. 24. 03:48
from collections import Counter anum,bnum=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) count1=Counter(a) count2=Counter(b) print(len(list((count1-count2).elements()))+len(list((count2-count1).elements())))
-
[백준] 10815. 숫자카드 (다시보기)코테 준비/Hash map 2023. 1. 19. 02:33
시간 초과 때문에 애먹음 import sys n=int(sys.stdin.readline()) nlist=list(map(int,sys.stdin.readline().split())) m=int(sys.stdin.readline()) mlist=list(map(int,sys.stdin.readline().split())) dict1={} for i in range(len(nlist)): dict1[nlist[i]]=0 #아무거나 넣기 (시간 단축위해서 dict사용하는거임) for i in mlist: if i in dict1: print(1,end=' ') else: print(0,end=' ')
-
9375. 패션왕 신해빈 ( 조합 공식의 중요성)코테 준비/Hash map 2023. 1. 5. 00:20
알몸을 제외한 모든 조합의 개수를 구하는 것이다. 공식을 옛날에 배웠었는데 공식을 모르면 못풀었을듯.... import sys from collections import defaultdict t=int(sys.stdin.readline()) for i in range(t): cloth_set=defaultdict(list) sum=1 n=int(sys.stdin.readline()) for j in range(n): cloth_name,cloth_kind=sys.stdin.readline().split() cloth_set[cloth_kind].append(cloth_name) for key in cloth_set: sum*=(len(cloth_set[key])+1) #각 옷 종류마다 (옷이름의 개수+1..
-
1620. 포켓몬 (17219. 비밀번호 찾기와 유사)코테 준비/Hash map 2023. 1. 3. 22:46
import sys n,m=map(int,sys.stdin.readline().split()) pocketmon={} pocketmon2={} for i in range(1,n+1): eng=sys.stdin.readline().rstrip() pocketmon[i]=eng pocketmon2[eng]=i for j in range(m): find=sys.stdin.readline().rstrip() if find.isdigit(): print(pocketmon[int(find)]) else: print(pocketmon2[find])
-
17219. 비밀번호 찾기 (딕셔너리 시간 단축)코테 준비/Hash map 2022. 12. 29. 17:51
import sys n,m=map(int,sys.stdin.readline().split()) password={} for i in range(n): s,p=sys.stdin.readline().split() password[s]=p for j in range(m): site=sys.stdin.readline().rstrip() print(password[site]) 딕셔너리를 사용하여 list보다 시간을 단축시킬 수 있다