結果
問題 |
No.2731 Two Colors
|
ユーザー |
|
提出日時 | 2024-04-26 03:03:38 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 866 bytes |
コンパイル時間 | 731 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 59,008 KB |
最終ジャッジ日時 | 2024-11-08 15:29:11 |
合計ジャッジ時間 | 7,388 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | WA * 33 |
ソースコード
from heapq import * EMPTY = -1 H, W = map(int, input().split()) nums = [list(map(int, input().split())) for _ in range(H)] cols = [[EMPTY] * 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]] for i in range(0,100): i2 = i % 2 a, (x, y) = heappop(Q[i2]) if cols[x][y] == EMPTY: 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] == EMPTY: heappush(Q[i2], (nums[x2][y2], (x2, y2)))