λ¬Έμ
https://www.acmicpc.net/problem/1780
1780λ²: μ’ μ΄μ κ°μ
N×Nν¬κΈ°μ νλ ¬λ‘ ννλλ μ’ μ΄κ° μλ€. μ’ μ΄μ κ° μΉΈμλ -1, 0, 1 μ€ νλκ° μ μ₯λμ΄ μλ€. μ°λ¦¬λ μ΄ νλ ¬μ λ€μκ³Ό κ°μ κ·μΉμ λ°λΌ μ μ ν ν¬κΈ°λ‘ μλ₯΄λ €κ³ νλ€. λ§μ½ μ’ μ΄κ° λͺ¨λ κ°μ μ
www.acmicpc.net
νμ΄
# λ°±μ€ 1780λ² λ¬Έμ - μ’
μ΄μ κ°μ
n = int(input())
board = [list(map(int, input().split())) for _ in range(n)]
result_minus = 0
result_zero = 0
result_plus = 0
def dfs(x,y,n):
global result_minus, result_zero, result_plus
num_check = board[x][y]
for i in range(x, x+n):
for j in range(y, y+n):
if (board[i][j] != num_check):
for k in range(3):
for l in range(3):
dfs(x + k*n // 3, y + l*n // 3, n // 3)
return
if num_check == -1:
result_minus += 1
elif num_check == 0:
result_zero += 1
else:
result_plus += 1
dfs(0,0,n)
print(f'{result_minus}\n{result_zero}\n{result_plus}')
'ποΈ Algorithm > π© λ°±μ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
π© [λ°±μ€] [Python] [DFS/BFS] 2667λ²_λ¨μ§λ²νΈλΆμ΄κΈ° (1) | 2022.11.04 |
---|---|
π© [λ°±μ€] [Python] [Class3] 1927λ²_μ΅μ ν (0) | 2022.11.04 |
π© [λ°±μ€] [Python] [ꡬν] 10815λ²_μ«μ μΉ΄λ (0) | 2022.11.03 |
π© [λ°±μ€] [Python] [ꡬν] 1010λ²_λ€λ¦¬ λκΈ° (0) | 2022.11.03 |
π© [λ°±μ€] [Python] [ꡬν] 14916λ²_κ±°μ€λ¦ λ_ (0) | 2022.11.03 |