DICTIONARY 3

[SW expert]5648 원자소멸시뮬레이션 #map

1. 풀이 처음에는 격자를 이용해서 풀려고 했다. (소스코드1) 0.5초 만에 만나는것을 구현하기 힘들어서 최대범위는 +-2000으로 했고, (x,y)를 (r,c)로 바꿔주기위해 r=2*x+2000, c=2*y+2000으로 하여 4000*4000의 격자를 만들어준 후 문제를 풀었다. 하지만 이 방법으로는 메모리 초과가 났다. ​ 따라서 아래와 같이 격자를 쓰지 않는 방법으로 문제를 풀었다. (1) atomD에 현재 원자들의 상태와 상태를 저장한다 (2) 이동시킨다 - 범위 밖이면 삭제한다 (이동할 때 원자가 범위 밖에서 만나는 경우는 없으므로) - 범위 안이면 cheakD에 저장하고, 바뀐 위치를 새롭게 atomD에 저장한다 (이때 cheakD는 dictionary형태로, key값을 (행,열)과 같은 튜..

알고리즘/구현 2020.06.18

[백준]나는야 포켓몬 마스터 이다솜 #dictionary

1. M에서 글자가 들어오면 index를 찾는 방식으로 구현했을때 시간초과가 발생. import sys N,M=map(int,input().split()) L=[] for i in range(N): L.append(sys.stdin.readline().rstrip()) for i in range(M): temp=sys.stdin.readline().rstrip() try: temp=int(temp)-1 print(L[temp]) except: print(L.index(temp)+1) 2. dictionary를 이용하여 key를 찾는 형식으로 했을 때 통과 import sys N,M=map(int,input().split()) dic1={} dic2={} for i in range(N): name=sys...

[백준]1764 듣보잡 #set,dict,list

list는 set과 dictionary 보다 요소를 찾는 속도가 느리다. ​ 1. list(시간초과) N,M=map(int,input().split()) L=[] for i in range(N): L.append(input()) ans=0 ansL=[] for i in range(M): temp=input() if temp in L: ans+=1 ansL.append(temp) L.remove(temp) print(ans) for i in sorted(ansL): print(i) 2. set(통과) N,M=map(int,input().split()) s=set() for i in range(N): word=input() s.add(word) ans=0 ansS=set() for j in range(M):..