[백준] 16197번 - 두 동전 (파이썬)
# 두 동전 import copy from collections import deque N, M = map(int, input().split()) arr = [] money = deque() for i in range(N): arr.append(list(input().strip())) for j in range(M): if arr[i][j] == 'o': money.append((i, j)) arr[i][j] = '.' visited = set() visited.add(''.join(map(str, money))) dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] def bfs(): q = deque() q.append((0, money)) while q: cnt, now = q.pop..
2022. 4. 20.
[백준] 2234번 - 성곽 (파이썬)
# 성곽 import sys from collections import deque from collections import defaultdict input = sys.stdin.readline M, N = map(int, input().split()) arr = [] for _ in range(N): arr.append(list(map(int, input().split()))) # 방향은 8,4,2,1 순서로 남,동,북,서 dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] def bfs(a, b, arr, visited, room_num): q = deque() q.append((a, b)) visited[a][b] = room_num room_size = 1 while q: x, y..
2022. 4. 17.
[백준] 24041번 - 성싶당 밀키트 (파이썬)
# 성싶당 밀키트 import sys from collections import defaultdict input = sys.stdin.readline N, G, K = map(int, input().split()) info = defaultdict(list) for _ in range(N): speed, limit, isImportant = map(int, input().split()) info[isImportant].append((speed, limit)) def get_g(x, k): result = 0 for speed, limit in info[0]: result += speed*max(1, x-limit) info[1].sort(key=lambda k: -k[0]*max(1, x-k[1])) f..
2022. 4. 15.
[백준] 1726번 - 로봇 (파이썬)
# 로봇 import sys from collections import deque input = sys.stdin.readline N, M = map(int, input().split()) arr = [list(map(int, input().split())) for _ in range(N)] sa, sb, sd = map(int, input().split()) ea, eb, ed = map(int, input().split()) dx = [0, 0, 0, 1, -1] dy = [0, 1, -1, 0, 0] def bfs(): q = deque() q.append((0, sa-1, sb-1, sd)) visited = [[[False for _ in range(5)] for _ in range(M)] fo..
2022. 4. 13.