-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18405.py
More file actions
46 lines (31 loc) · 878 Bytes
/
18405.py
File metadata and controls
46 lines (31 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
virus = []
land = [[] for _ in range(n)]
for i in range(n):
land[i] = list(map(int, input().split()))
for j in range(n):
if land[i][j] != 0:
virus.append((land[i][j], i, j, 0))
virus.sort()
s, x, y = map(int, input().split())
visited = [[False] * n for _ in range(n)]
from collections import deque
q = deque(virus)
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
while q:
virusNum, xx, yy, time = q.popleft()
visited[xx][yy] = True
if time == s:
break
for i in range(4):
nx = xx + dx[i]
ny = yy + dy[i]
if 0 <= nx < n and 0 <= ny < n:
if not visited[nx][ny]:
land[nx][ny] = virusNum
visited[nx][ny] = True
q.append((virusNum, nx, ny, time + 1))
print(land[x-1][y-1])