結果
| 問題 |
No.2731 Two Colors
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-19 22:39:02 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,014 bytes |
| コンパイル時間 | 360 ms |
| コンパイル使用メモリ | 82,152 KB |
| 実行使用メモリ | 137,576 KB |
| 最終ジャッジ日時 | 2024-10-11 16:22:15 |
| 合計ジャッジ時間 | 30,339 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 TLE * 3 |
ソースコード
from heapq import heapify, heappop, heappush
H, W = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
visited = [[None for _ in range(W)] for _ in range(H)]
visited[0][0] = 0
visited[H-1][W-1] = 1
hq = [[], []]
heapify(hq[0]); heapify(hq[1])
for i, xy in enumerate([[0, 0], [H-1, W-1]]):
x, y = xy
for dx, dy in [(1,0), (-1,0), (0,1), (0,-1)]:
_x = x+dx
_y = y+dy
if (not 0 <= _x < H) or (not 0 <= _y < W):
continue
heappush(hq[i], [A[_x][_y], _x, _y])
i = 0
while True:
ii = i % 2
a, x, y = heappop(hq[ii])
if visited[x][y] != None:
continue
visited[x][y] = ii
for dx, dy in [(1,0), (-1,0), (0,1), (0,-1)]:
_x = x+dx
_y = y+dy
if (not 0 <= _x < H) or (not 0 <= _y < W):
continue
if visited[_x][_y] == ii:
continue
if visited[_x][_y] == (ii+1) % 2:
exit(print(i+1))
heappush(hq[ii], [A[_x][_y], _x, _y])
i += 1