結果

問題 No.2731 Two Colors
ユーザー hotate29hotate29
提出日時 2024-04-19 21:58:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 934 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 130,980 KB
最終ジャッジ日時 2024-04-19 21:59:39
合計ジャッジ時間 27,053 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 AC 117 ms
76,672 KB
testcase_04 AC 163 ms
78,696 KB
testcase_05 AC 168 ms
78,756 KB
testcase_06 AC 308 ms
86,716 KB
testcase_07 AC 257 ms
83,592 KB
testcase_08 AC 156 ms
78,088 KB
testcase_09 AC 583 ms
104,736 KB
testcase_10 AC 127 ms
77,520 KB
testcase_11 AC 1,101 ms
129,636 KB
testcase_12 AC 499 ms
103,612 KB
testcase_13 AC 887 ms
120,284 KB
testcase_14 AC 332 ms
90,052 KB
testcase_15 AC 152 ms
78,408 KB
testcase_16 AC 478 ms
95,840 KB
testcase_17 AC 513 ms
99,384 KB
testcase_18 AC 226 ms
80,996 KB
testcase_19 AC 474 ms
96,564 KB
testcase_20 AC 337 ms
91,760 KB
testcase_21 AC 222 ms
81,404 KB
testcase_22 AC 743 ms
115,220 KB
testcase_23 AC 302 ms
86,632 KB
testcase_24 AC 224 ms
81,036 KB
testcase_25 AC 112 ms
77,108 KB
testcase_26 AC 541 ms
103,036 KB
testcase_27 AC 643 ms
109,940 KB
testcase_28 AC 647 ms
105,040 KB
testcase_29 AC 282 ms
85,048 KB
testcase_30 AC 323 ms
89,584 KB
testcase_31 AC 340 ms
87,632 KB
testcase_32 AC 1,010 ms
130,980 KB
testcase_33 AC 36 ms
52,608 KB
testcase_34 AC 37 ms
52,608 KB
testcase_35 AC 37 ms
52,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush

h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

# くっつくまでやる
a_q = [(a[0][0], 0, 0)]
b_q = [(a[-1][-1], h - 1, w - 1)]

colors = [[-1] * w for _ in range(h)]

go = True
turn = 0
cnt = 0
DXDY = [(1, 0), (0, 1), (-1, 0), (0, -1)]

while go:
    # print(a_q, b_q, turn)

    if turn == 0:
        _, y, x = heappop(a_q)
    else:
        _, y, x = heappop(b_q)

    if colors[y][x] != -1:
        continue

    colors[y][x] = turn
    for dx, dy in DXDY:
        nx, ny = x + dx, y + dy
        if 0 <= nx < w and 0 <= ny < h:
            if colors[ny][nx] == -1:
                if turn == 0:
                    heappush(a_q, (a[ny][nx], ny, nx))
                else:
                    heappush(b_q, (a[ny][nx], ny, nx))
            elif colors[ny][nx] != turn:
                go = False

    turn = 1 - turn
    cnt += 1

print(cnt - 2)
0