Upload files to "백준"

This commit is contained in:
2026-04-11 11:55:44 +09:00
parent 00408f112d
commit 74f2368092
5 changed files with 147 additions and 0 deletions

41
백준/2206.py Normal file
View File

@@ -0,0 +1,41 @@
import sys
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
graph = defaultdict(list)
n, m = map(int, input().split())
arr = []
for i in range(n):
arr.append(list(map(int, input().strip())))
dist = [[[0 for _ in range(2)] for _ in range(m)] for _ in range(n)]
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
now_x, now_y = 0, 0
q = deque([(0, 0, False)])
dist[0][0][0] = 1
while q:
x, y, jump = q.popleft()
if x == m-1 and y == n-1:
print(dist[y][x][jump])
sys.exit(0)
for dx, dy in ((x+1, y), (x, y+1), (x-1, y), (x, y-1)):
if 0<=dx<m and 0<=dy<n:
if arr[dy][dx] == 0 and dist[dy][dx][jump] == 0:
q.append((dx, dy, jump))
dist[dy][dx][jump] = dist[y][x][jump] + 1
elif arr[dy][dx] == 1 and jump == False and dist[dy][dx][1] == 0:
q.append((dx, dy, True))
dist[dy][dx][1] = dist[y][x][jump] + 1
print(-1)

27
백준/2252.py Normal file
View File

@@ -0,0 +1,27 @@
import sys
from collections import deque
input = sys.stdin.readline
N, M = map(int, input().split())
A = [[] for _ in range(N+1)]
indegree = [0] * (N+1)
for i in range(M):
S, E = map(int, input().split())
A[S].append(E)
indegree[E] += 1
queue = deque()
for i in range(1, N+1):
if indegree[i] == 0:
queue.append(i)
while queue:
now = queue.popleft()
print(now, end=' ')
for next in A[now]:
indegree[next]-=1
if indegree[next] == 0:
queue.append(next)

10
백준/2342.py Normal file
View File

@@ -0,0 +1,10 @@
import sys
input = sys.stdin.readline
arr = list(map(int, input().split()))
ddr = [[0 for i in range(2)] for j in range(len(arr))]
def score()
for index in arr:

32
백준/2343.py Normal file
View File

@@ -0,0 +1,32 @@
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
N, M = map(int, input().split())
lst = list(map(int, input().split()))
min_lst = max(lst)
max_lst = sum(lst)
result = max_lst
while min_lst <= max_lst:
avg_lst = (max_lst + min_lst) // 2
sum = 0
tot = 1
for i in lst:
if(sum + i > avg_lst):
tot += 1
sum = i
else :
sum += i
if(tot > M): # 용량을 줄여야 하는 상태
min_lst = avg_lst + 1
else:
result = avg_lst
max_lst = avg_lst - 1
print(result)

37
백준/2696.py Normal file
View File

@@ -0,0 +1,37 @@
import sys
import queue
from heapq import heappush, heappop
input = sys.stdin.readline
T = int(input())
for _ in range(T):
M = int(input())
max_heap = []
min_heap = []
result = []
numbers = []
while len(numbers) < M:
numbers.extend(list(map(int, input().split())))
for i in range(M):
num = numbers[i]
if(len(max_heap)<=len(min_heap)):
heappush(max_heap,-num)
else:
heappush(min_heap, num)
if min_heap and -max_heap[0] > min_heap[0]:
temp_max = -heappop(max_heap)
temp_min = heappop(min_heap)
heappush(max_heap, -temp_min)
heappush(min_heap, temp_max)
if (i + 1) % 2 == 1:
result.append(-max_heap[0])
print(len(result))
for i in range(0, len(result), 10):
print(*result[i:i+10])