๐ฅ Silver1https://www.acmicpc.net/problem/21937 โ
์ ๋ต์ฝ๋import sysinput = sys.stdin.readlinedef dfs(idx): stack.append(idx) visited[idx] = True while stack: cur = stack.pop() for i in graph[cur]: if not visited[i]: stack.append(i) visited[i] = True answer.add(i)n, m = map(int, input().strip().split())graph = [[] fo..
๐ฅ Silver2 https://www.acmicpc.net/problem/7562 โ
์ ๋ตํ์ดimport sysfrom collections import dequeinput = sys.stdin.readlinedx = [1, 2, 2, 1, -1, -2, -2, -1]dy = [2, 1, -1, -2, -2, -1, 1, 2]def bfs(start_x, start_y, end_x, end_y, length): queue = deque([(start_x, start_y)]) visited = [[-1] * length for _ in range(length)] # ๋ชจ๋ ๊ฐ์ -1๋ก ์ด๊ธฐํ visited[start_x][start_y] = 0 # ์์ ์ง์ ์ ์ด๋ ๊ฑฐ๋ฆฌ 0์ผ๋ก ์ค..
๐ฅ Silver3 https://www.acmicpc.net/problem/2606 โ
์ ๋ตํ์ด : DFSdef dfs(idx): stack=[idx] #stack.append(idx) visited[idx]=True while stack: cur=stack.pop() for adj in graph[cur]: if not visited[adj]: visited[adj]=True stack.append(adj)# ๊ทธ๋ํ ์ด๊ธฐ ์ค์ n=int(input())graph=[[] for _ in range(n+1)] #0๋ฒ์งธ ์ธ๋ฑ์ค๋ ๋น๋ฐฐ์ด๋กfor _ in range(int(input())):..
๐ฅSilver2https://www.acmicpc.net/problem/2644 โ
์ ๋ตํ์ดimport sysfrom collections import dequeinput = sys.stdin.readlinedef bfs(start,end): queue=deque([start]) visited[start]=0 # ์์์ง์ : ๊ฑฐ๋ฆฌ 0 while queue: cur=queue.popleft() # ๋ชฉํ ์ง์ ๋๋ฌํ๋ฉด ๊ฑฐ๋ฆฌ ๋ฐํ if cur==end: return visited[cur] # ์ธ์ ๋
ธ๋ ๋ฐฉ๋ฌธ for neighbor in graph[cur]: if visit..
๐ฅ Silver2https://www.acmicpc.net/problem/1072 โ 1์ฐจ์๋import sysinput=sys.stdin.readlinen,m=map(int,input().strip().split())if n==m: print(-1)else: z=int(m/n*100) # ์น๋ฅ Z start=1 end=n result=0 while start ์ค๋ต์ ์์ธ์ ์๋ชป ์ ์ํ ์น๋ฅ ๊ณผ ์ ๋ ๋ณํ์ง ์๋ ์น๋ฅ ์ผ๋ -1์ ์ถ๋ ฅํ๋ ์กฐ๊ฑด๋ฌธ์ด์๋ค.์ ๋ ์น๋ฅ ์ด ๋ณํ์ง ์๋ ๊ฒฝ์ฐ๋ 100%์ด๊ธฐ ๋๋ฌธ์ ๊ฒ์ํ์์ ์ด๊ธด๊ฒ์์ด ๊ฐ์๋๋ผ๋ ์กฐ๊ฑด์ผ๋ก ์์ฑํ์๋ค. โ๏ธ ๊ทผ๋ฐ ๊ฐ๊ณผํ์ ์ด ์๋ค.์น๋ฅ 99% ๋ํ 100%๋ฅผ ๋ง๋ค ์ ์๋ค. 99.999%๋ผ๊ณ ํ๋๋ผ๋ ๋จ ํ..
๐ฅ silver2 โ
1์ฐจํ์ด : setimport sysinput=sys.stdin.readlinen=int(input())sangs=set(map(int,input().rstrip().split()))m=int(input())num_set=list(map(int,input().rstrip().split()))for s in num_set: # print(s) if s in sangs: print(1,end=' ') else: print(0,end=' ')๋ฉ๋ชจ๋ฆฌ์คํ์๊ฐ125620612 ์ค๋ณต๋ ๊ฐ์ ๋ํ ์ค๋ฆ์ฐจ์ ์ ๋ ฌ ์์๋ฅผ ์ํด์, set์ ์ฌ์ฉํ์๋ค. โ
2์ฐจํ์ด : binary Searchimport sysinput = sys.stdin.readlinen..
๐ฅ Bronze1https://www.acmicpc.net/problem/16466 โ
์ ๋ตํ์ดimport sysinput = sys.stdin.readlineN = int(input())first_tickets = sorted(map(int, input().split())) isEnd=Truefor i in range(N): #0 1 2 3 4 if i+1!=first_tickets[i]: print(i+1) isEnd=False break#1์ฐจ์์ ๋คํ๋ฆฐ ๊ฒฝ์ฐif isEnd: print(N+1) ๋ฉ๋ชจ๋ฆฌ์คํ์๊ฐ155528340 ์ฒ์์ list๋ฅผ ์ํํ๋ฉด์ in์ฐ์ฐ์๋ก ์ฒดํฌ๋ฅผ ํด๋ณด๋ ๋ฐฉ์์ผ๋ก ํ์๋๋ฐ, ์๊ฐ์ด๊ณผ๊ฐ ๋ฐ์ํ๋ค..๊ทธ๋์ in ์ฐ์ฐ์๊ฐ ๋ชจ๋ ์..
๐ฅ Silver2https://www.acmicpc.net/problem/1654 โ
์ ๋ตํ์ดimport sysinput=sys.stdin.readlinen,k=map(int,input().split())lines=[int(input()) for _ in range(n)]answer=1left=1right=2**31-1#binary Searchwhile left=k: #์ค๋ฅธ์ชฝ ๋ณด๊ธฐ answer=mid left=mid+1 else: right=mid-1print(answer)๋ฉ๋ชจ๋ฆฌ์คํ์๊ฐ31120KB88ms ์ด๋ถํ์์ ๊ตญ๋ฃฐ mid ์ฐพ๊ณ , target๊ฐ์ ํฌ๊ธฐ ๋น๊ต๋ก ์ธํด left, right๊ฐ ์
๋ฐ์ดํธ ํด์ฃผ๊ธฐํ์ง๋ง ์ฒ์์ count(๋ง๋ ๊ฐ์)==k(..