boj step 9 rework & aloha graph1(16174,2606,1520)
This commit is contained in:
4
zeta_python/completed/1271.py
Normal file
4
zeta_python/completed/1271.py
Normal file
@@ -0,0 +1,4 @@
|
||||
a, b = map(int, input().split())
|
||||
|
||||
print(a // b)
|
||||
print(a % b)
|
||||
32
zeta_python/completed/1520.py
Normal file
32
zeta_python/completed/1520.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import sys
|
||||
|
||||
sys.setrecursionlimit(1 << 16)
|
||||
|
||||
|
||||
def solve(M, N, U):
|
||||
"""get count of pathes"""
|
||||
|
||||
Mem = [[-1 for _ in range(N)] for _ in range(M)]
|
||||
Mem[M - 1][N - 1] = 1
|
||||
|
||||
def dfs(now):
|
||||
x, y = now
|
||||
if Mem[x][y] != -1:
|
||||
return Mem[x][y]
|
||||
cnt = 0
|
||||
for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
|
||||
_x, _y = x + i, y + j
|
||||
if 0 <= _x < M and 0 <= _y < N and U[_x][_y] < U[x][y]:
|
||||
cnt += dfs((_x, _y))
|
||||
|
||||
Mem[x][y] = cnt
|
||||
return Mem[x][y]
|
||||
|
||||
dfs((0, 0))
|
||||
return Mem[0][0]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
M, N = map(int, input().split())
|
||||
U = [list(map(int, input().split())) for _ in range(M)] # U[m][n]
|
||||
print(solve(M, N, U))
|
||||
33
zeta_python/completed/16174.py
Normal file
33
zeta_python/completed/16174.py
Normal file
@@ -0,0 +1,33 @@
|
||||
def solve(N, A) -> bool:
|
||||
now = (0, 0)
|
||||
D = []
|
||||
D.append(now)
|
||||
X = [[0 for _ in range(N)]for _ in range(N)]
|
||||
while D:
|
||||
now = D.pop()
|
||||
amount = A[now[0]][now[1]]
|
||||
if X[now[0]][now[1]]:
|
||||
continue
|
||||
X[now[0]][now[1]] = 1
|
||||
if amount == 0:
|
||||
continue
|
||||
elif amount == -1:
|
||||
return True
|
||||
if now[0] + amount >= N:
|
||||
pass
|
||||
else:
|
||||
target = (now[0] + amount, now[1])
|
||||
D.append(target)
|
||||
if now[1] + amount >= N:
|
||||
pass
|
||||
else:
|
||||
target = (now[0], now[1] + amount)
|
||||
D.append(target)
|
||||
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
N = int(input())
|
||||
A = [list(map(int, input().split())) for _ in range(N)]
|
||||
print("HaruHaru" if solve(N, A) else "Hing")
|
||||
30
zeta_python/completed/2606.py
Normal file
30
zeta_python/completed/2606.py
Normal file
@@ -0,0 +1,30 @@
|
||||
def solve(N, X, E):
|
||||
ComputerMap = {}
|
||||
WormMap = [0 for i in range(N + 1)]
|
||||
WormMap[1] = 1
|
||||
for i in range(1, N + 1):
|
||||
ComputerMap[i] = []
|
||||
for e in E:
|
||||
ComputerMap[e[0]].append(e[1])
|
||||
ComputerMap[e[1]].append(e[0])
|
||||
|
||||
D = []
|
||||
D.append(1)
|
||||
while D:
|
||||
x = D.pop()
|
||||
connected = ComputerMap[x]
|
||||
for conn in connected:
|
||||
if WormMap[conn]:
|
||||
continue
|
||||
else:
|
||||
WormMap[conn] = 1
|
||||
D.append(conn)
|
||||
|
||||
return sum(WormMap) - 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
N = int(input())
|
||||
X = int(input())
|
||||
E = list(sorted(list(map(int, input().split()))) for _ in range(X))
|
||||
print(solve(N, X, E))
|
||||
Reference in New Issue
Block a user