結果

問題 No.2731 Two Colors
ユーザー 👑 rin204rin204
提出日時 2024-04-20 01:18:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 871 bytes
コンパイル時間 426 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 135,372 KB
最終ジャッジ日時 2024-04-20 01:18:25
合計ジャッジ時間 17,001 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,367 ms
135,248 KB
testcase_01 AC 1,382 ms
135,124 KB
testcase_02 AC 1,385 ms
135,372 KB
testcase_03 AC 86 ms
77,108 KB
testcase_04 AC 110 ms
79,280 KB
testcase_05 AC 115 ms
78,640 KB
testcase_06 AC 193 ms
83,144 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 721 ms
113,128 KB
testcase_12 WA -
testcase_13 AC 625 ms
108,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 350 ms
95,456 KB
testcase_18 AC 148 ms
79,340 KB
testcase_19 WA -
testcase_20 AC 280 ms
93,628 KB
testcase_21 AC 159 ms
79,584 KB
testcase_22 AC 531 ms
109,728 KB
testcase_23 WA -
testcase_24 AC 134 ms
79,808 KB
testcase_25 WA -
testcase_26 AC 402 ms
101,808 KB
testcase_27 WA -
testcase_28 AC 464 ms
99,028 KB
testcase_29 WA -
testcase_30 AC 235 ms
86,928 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 34 ms
53,204 KB
testcase_34 AC 34 ms
53,716 KB
testcase_35 AC 33 ms
52,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = 0
used1[0][0] = True
used2[h - 1][w - 1] = True

di = [1, 0, -1, 0]
dj = [0, 1, 0, -1]

while 1:
    ans += 1
    a, i, j = heappop(hq1)
    used[i][j] = ans % 2
    for k in range(4):
        ni, nj = i + di[k], j + dj[k]
        if ni == -1 or ni == h or nj == -1 or nj == w:
            continue
        if not used1[ni][nj]:
            if used[ni][nj]:
                print(ans - 2)
                exit()
            else:
                heappush(hq1, (A[ni][nj], ni, nj))
            used1[ni][nj] = True

    hq1, hq2 = hq2, hq1
    used1, used2 = used2, used1
0