π¨π»π» PS/PYTHON
[νμ΄μ¬ PYTHON] λ°±μ€ 2146λ² γλ€λ¦¬ λ§λ€κΈ°γ
import sys from collections import deque N = int(input()) _map = [list(map(int, sys.stdin.readline().split())) for _ in range(N)] dr = [1, -1, 0, 0] dc = [0, 0, 1, -1] # μ¬ λΌλ²¨λ§ def labeling(label): while queue: r, c = queue.popleft() for i in range(4): nr = dr[i] + r nc = dc[i] + c if 0
[νμ΄μ¬ PYTHON] λ°±μ€ 2638λ² γμΉμ¦γ
import sys from collections import deque import copy row, col = map(int, input().split()) _map = [list(map(int, sys.stdin.readline().split())) for _ in range(row)] queue = deque([]) checked = [[False]*col for _ in range(row)] dr = [1, -1, 0, 0] dc = [0, 0, 1, -1] def bfs(): copiedCheck = copy.deepcopy(checked) queue.append([0, 0]) while queue: r, c = queue.popleft() for i in range(4): nr = r + d..
[νμ΄μ¬ PYTHON] λ°±μ€ 16236λ² γμκΈ° μμ΄γ
import sys import copy from collections import deque # μμ μ λ ₯ N = int(input()) _map = [[0]*N for _ in range(N)] checked = [[False]*N for _ in range(N)] queue = deque([]) for i in range(N): info = list(map(int,sys.stdin.readline().split())) for j in range(N): _map[i][j]=info[j] if info[j] == 9: _map[i][j] = 0 shark = [i,j,0] queue.append(shark) # bfs()λ‘ λ¨Ήμ μ μλ λ¨Ήμ΄ νμνκΈ° dr = [1,-1,0,0] dc = [0,0,1,..
[νμ΄μ¬ PYTHON] λ°±μ€ 14502λ² γμ°κ΅¬μγ
import copy import sys from collections import deque # μμ μ λ ₯ row,col= map(int,input().split()) _map = [[0]*col for _ in range(row)] for i in range(row): info = list(map(int,sys.stdin.readline().split())) for j in range(col): _map[i][j]=info[j] queue = deque([]) # λ°μ΄λ¬μ€ μμΉ μ μ₯ for i in range(row): for j in range(col): if _map[i][j] == 2: queue.append([i,j]) dr = [1,-1,0,0] dc = [0,0,1,-1] ans = -1e..
[νμ΄μ¬ PYTHON] λ°±μ€ 15686λ² γμΉν¨ λ°°λ¬γ
import sys #μμ μ λ ₯ N,M = map(int,sys.stdin.readline().split()) _map = [list(map(int,sys.stdin.readline().split())) for _ in range(N)] chickens = [] houses = [] # μ§κ³Ό μΉν¨μ§ μ’ν μ μ₯ for row in range(N): for col in range(N): if _map[row][col] == 2: chickens.append([row,col]) elif _map[row][col] == 1: houses.append([row,col]) selected = [] checked = [False]*(len(chickens)) ans = 1e9 def getMinDistance(sel..
[νμ΄μ¬ PYTHON] λ°±μ€ 15684λ² γμ¬λ€λ¦¬ μ‘°μγ
import sys # μμ μ λ ₯ N, M, H = map(int, sys.stdin.readline().split()) ladders = [list(map(int, sys.stdin.readline().split())) for _ in range(M)] _map = [[0] * N for _ in range(H)] # μ¬λ€λ¦¬ μ 보 μ μ₯ # μΌμͺ½μ 1 μ€λ₯Έμͺ½μ -1λ‘ μ μ₯ for ladder in ladders: ladderR = ladder[0] - 1 ladderC = ladder[1] - 1 _map[ladderR][ladderC] = 1 _map[ladderR][ladderC + 1] = -1 # λͺ¨λ iλ² κ²°κ³Όκ° iλ² μΈκ°? def isEqual(): for i in range(N): locat..
[νμ΄μ¬ PYTHON] μ½λν¬μ€ 1426D
Problem - 1426D - Codeforces codeforces.com μμ΄μ΄ μ£Όμ΄μ§λλ°, νΉμ λΆλΆν©μ΄ 0μ΄ λμ§ μλλ‘ νλ μ΅μ νμλ₯Ό ꡬνλ λ¬Έμ μ΄λ€. μλ‘ 1 -5 3 2 μμ κ°μ μμ΄μ΄ μμ λ, {-5, 3, 2} μ ν©μ 0μ΄ λλ―λ‘ 1 -5 3 {Block} 2 μ λͺ¨μ μ²λΌ μ¬μ΄λ₯Ό λμ΄λμΌ νκ³ 1λ²μΌλ‘ μΆ©λΆνλ―λ‘ λ΅μ 1μ΄λ€. 16 -5 -11 -15 10 5 4 -4 μμ κ²½μ°λ 16 -5 {Block} -11 -15 10 {Block} 5 4 {Block} -4 μ΄ 3λ²μ λ§μμΌ λΆλΆν©μ΄ 0μ΄ λ μ μλ€. μ΄ λ¬Έμ λ, ꡬκ°ν© μκ³ λ¦¬μ¦μ μ¬μ©ν΄μΌνλ€. · κ΅¬κ° ν© μκ³ λ¦¬μ¦ (Prefix Sum Algorithm) π©π»π» μ§μ μ°½κ³ π inkyu-yoon.github.io..
[νμ΄μ¬ PYTHON] λ°±μ€ 3190λ² γλ±γ
from collections import deque boardSize = int(input()) appleNum = int(input()) # 맡 μμ± board = [[0]*boardSize for _ in range(boardSize)] # μ¬κ³Ό μμΉ μ μ₯ (1λ‘ νμ) for _ in range(appleNum): row,col=map(int,input().split()) board[row-1][col-1] = 1 # λͺ λ Ή μ μ₯ (key : value λ‘) commands = {} commandNum = int(input()) for _ in range(commandNum): sec,command = map(str,input().split()) commands[int(sec)]=command # ..
[νμ΄μ¬ PYTHON] λ°±μ€ 2812λ² γν¬κ² λ§λ€κΈ°γ
λ¬Έμ μ κ·Ό λ°©λ²μ μμ λ‘ μ€λͺ ν΄λ³΄κ² λ€. 10 4 4177252841 μμ κ°μ΄ 10κ°μ μ«μκ° μ£Όμ΄μ§κ³ , 4κ°μ μ«μλ₯Ό μμ ν μ μλ€. κ°μ₯ ν° μλ₯Ό μΆλ ₯νκΈ° μν΄μλ, μμ μ리μκ° μ»€μΌνλ€. μ μ리 μλΆν° νλμ© μ€νμ λ£μ κ²μΈλ°, μ€νμ λ€μ΄κ° μκ° μ€νμ λ€μ΄μλ μλ³΄λ€ ν° κ²½μ° & μμ νμκ° λ¨μμλ κ²½μ° μ€νμ μλ μ«μλ₯Ό μ§μΈ κ²μ΄λ€. μμλ‘ λ³΄λ©΄ νμ¬ answer μ€ν = [] μ λΉμ΄μλ€. 4177252841 μλ₯Ό μ μ리 μλΆν° λ£μ κ²μ΄λ€. answer μ€νμ λΉκ΅ν μκ° μμΌλ―λ‘ μ²«λ²μ§Έ μ리λ μΌλ¨ μ€νμ μ λ ₯νλ€. answer = [ 4 ] 4 177252841 μ΄μ 1μ λ£μ μ°¨λ‘μΈλ°, answer μ€ν μμ μλ 4κ° λ ν¬λ―λ‘ μΌλ¨ μ λ ₯νλ€. answer = [ 4 1..