結果
| 問題 |
No.2731 Two Colors
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-26 02:59:27 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 864 bytes |
| コンパイル時間 | 630 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 69,888 KB |
| 最終ジャッジ日時 | 2024-11-08 15:24:32 |
| 合計ジャッジ時間 | 11,843 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 32 |
ソースコード
from heapq import *
NUL = -1
H, W = map(int, input().split())
nums = [list(map(int, input().split())) for _ in range(H)]
cols = [[NUL] * W for _ in range(H)]
cols[0][0] = 0
cols[H - 1][W - 1] = 1
q0 = [(nums[0][1], (0, 1)), (nums[1][0], (1, 0))]
heapify(q0)
q1 = [(nums[H - 1][W - 2], (H - 1, W - 2)), (nums[H - 2][W - 1], (H - 2, W - 1))]
heapify(q1)
Q = [q0, q1]
dirs = [[0, 1], [1, 0], [-1, 0], [0, -1]]
i = 0
while 1:
i2 = i % 2
a, (x, y) = heappop(Q[i2])
if cols[x][y] == NUL:
cols[x][y] = i2
for xd, yd in dirs:
x2 = x + xd
y2 = y + yd
if 0 <= x2 < H and 0 <= y2 < W:
if cols[x2][y2] == i2 ^ 1:
print(i + 1)
exit()
elif cols[x2][y2] == -1:
heappush(Q[i2], (nums[x2][y2], (x2, y2)))
i += 1