結果
問題 | No.2731 Two Colors |
ユーザー |
👑 |
提出日時 | 2024-04-20 01:20:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,524 ms / 3,000 ms |
コード長 | 846 bytes |
コンパイル時間 | 545 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 119,864 KB |
最終ジャッジ日時 | 2024-10-11 20:10:38 |
合計ジャッジ時間 | 17,773 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
from heapq import *h, w = map(int, input().split())A = [list(map(int, input().split())) for _ in range(h)]hq1 = [(A[0][0], 0, 0)]hq2 = [(A[h - 1][w - 1], h - 1, w - 1)]used = [[False] * w for _ in range(h)]used1 = [[False] * w for _ in range(h)]used2 = [[False] * w for _ in range(h)]ans = 0used1[0][0] = Trueused2[h - 1][w - 1] = Truedi = [1, 0, -1, 0]dj = [0, 1, 0, -1]while 1:ans += 1a, i, j = heappop(hq1)used[i][j] = Truefor k in range(4):ni, nj = i + di[k], j + dj[k]if ni == -1 or ni == h or nj == -1 or nj == w:continueif not used1[ni][nj]:if used[ni][nj]:print(ans - 2)exit()heappush(hq1, (A[ni][nj], ni, nj))used1[ni][nj] = Truehq1, hq2 = hq2, hq1used1, used2 = used2, used1