본문 바로가기

분류 전체보기263

[백준] 1325번 - 효율적인 해킹 (파이썬) # 효율적인 해킹 import sys from collections import deque input = sys.stdin.readline def count(where): q = deque() q.append(where) visited = [False] * (N+1) visited[where] = True cnt = 1 while q: node = q.popleft() for nnode in arr[node]: if not visited[nnode]: q.append(nnode) cnt += 1 visited[nnode] = True return cnt N, M = map(int, input().split()) arr = [[] for _ in range(N+1)] for _ in range(M): a,.. 2022. 1. 20.
[백준] 2178번 - 미로 탐색 (파이썬) # 미로 탐색 import sys from collections import deque input = sys.stdin.readline def go(x, y): q = deque() q.append((x, y)) while q: x, y = q.popleft() for i in range(4): nx = x + dx[i] ny = y + dy[i] if nx = N or ny = M: continue if arr[nx][ny] == 0: continue elif arr[nx][ny] == 1: q.append((nx, ny)) arr[nx][ny] = arr[x][y] + 1 N, M = map(int, input().split()) arr = [] for i in range(N): arr.append(.. 2022. 1. 20.
[백분] 13913번 - 숨바꼭질 3 (파이썬) # 숨바꼭질 3 from collections import deque def bfs(): q = deque() q.append(N) while q: now = q.popleft() if now == M: return visited[now] for k in [now-1, now+1, now*2]: nnow = k if 0 2022. 1. 20.
[백준] 1806번 - 부분합 (파이썬) # 부분합 import sys MAX = sys.maxsize input = sys.stdin.readline N, S = map(int, input().split()) arr = list(map(int, input().split())) end = 0 sum = 0 result = MAX for start in range(N): while end = S: result = min(result, end-start) sum -= arr[start] if result == MAX: print(0) else: print(result) 투포인터 1. start와 end로 연속되는 수열의 합(sum)을 구하고 목표값과 비교 2... 2022. 1. 20.