본문 바로가기

분류 전체보기

(402)
[백준 10999번] 구간 합 구하기 2 (Python3) import sys input = sys.stdin.readline def make(i,v,s,e,x): seg[x] += v if s==e: return mid = (s+e)//2 if i
[백준 1040번] 정수 (Python3) from itertools import * def solve(): if len({*N})==K: return N for i in range(1,len(N)+1): result = [] inuse = {*(N0:=N[:-i])}; notuse = {*map(str,range(10))}-inuse; k = K-len(inuse) if 0
[백준 5022번] 연결 (Python3) from collections import * dy = [1,-1,0,0]; dx = [0,0,1,-1] def BFS(A1,A2): dq = deque([[*A1,*A1,0]]) while dq: y,x,ylast,xlast,d = dq.popleft() if visited[y][x]: continue visited[y][x] = ylast,xlast if [y,x] == A2: return d for i in range(4): y1,x1 = y+dy[i],x+dx[i] if N>y1>=0 and M>x1>=0: dq.append((y1,x1,y,x,d+1)) return 1e6 def solve(A1,A2,B1,B2): global visited visited = [[0]*M for i in rang..
[백준 2191번] 들쥐의 탈출 (Python3) def DFS(i): if visited[i]: return visited[i] = 1 for j in graph[i]: if match[j]
[백준 11014번] 컨닝 2 (Python3) def DFS(y,x): if visited[y][x]: return 0 visited[y][x] = 1 for y1,x1 in graph[y][x]: if not match[y1][x1]: match[y1][x1] = y,x return 1 for y1,x1 in graph[y][x]: if DFS(*match[y1][x1]): match[y1][x1] = y,x return 1 return 0 for _ in range(int(input())): N,M = map(int,input().split()) board = [[*map(lambda x:int(x=="."),input())] for i in range(N)] graph = [[[] for x in range(M)] for y in range(N..
[백준 11377번] 열혈강호 3 (Python3) import sys input = sys.stdin.readline def DFS(i): if visited[i]: return 0 visited[i] = 1 for w in graph[i]: if work[w]
[백준 1020번] 디지털 카운터 (Python3) from itertools import combinations_with_replacement as comb def solve(): for c in range(1,C+1): N0 = N[-c:] S = sum(cnt[int(n)] for n in N0) result = [] for pick in comb(num,c): if sum(pick)==S: for n in range(int(N0[0])+1,10): if cnt[n] in pick: pick = [*pick] pick.remove(cnt[n]) result.append(int(str(n)+"".join(map(str,sorted(num[n] for n in pick))))) break if result: return min(result)-int(N0..
[백준 1824번] 도미노 (Python3) dy = [1,-1,0,0]; dx = [0,0,1,-1] def DFS(y,x): if visited[y][x]: return visited[y][x] = 1 for y1,x1 in graph[y][x]: if not match[y1][x1]: match[y1][x1] = y,x return 1 for y1,x1 in graph[y][x]: if DFS(*match[y1][x1]): match[y1][x1] = y,x return 1 N,M = map(int,input().split()) graph = [[set() for x in range(M)] for y in range(N)] for y in range(N): for x in range(M): if (y+x)%2: continue for i in..