結果

問題 No.2731 Two Colors
ユーザー hotate29hotate29
提出日時 2024-04-19 21:56:26
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 934 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 131,016 KB
最終ジャッジ日時 2024-04-19 21:57:48
合計ジャッジ時間 26,497 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 AC 110 ms
76,800 KB
testcase_04 AC 156 ms
78,856 KB
testcase_05 AC 157 ms
78,468 KB
testcase_06 AC 290 ms
86,332 KB
testcase_07 AC 260 ms
83,836 KB
testcase_08 AC 134 ms
77,824 KB
testcase_09 AC 539 ms
104,336 KB
testcase_10 AC 130 ms
77,760 KB
testcase_11 AC 1,061 ms
129,504 KB
testcase_12 AC 480 ms
103,308 KB
testcase_13 AC 868 ms
120,028 KB
testcase_14 AC 331 ms
90,444 KB
testcase_15 AC 158 ms
78,528 KB
testcase_16 AC 485 ms
95,816 KB
testcase_17 AC 490 ms
99,016 KB
testcase_18 AC 221 ms
81,516 KB
testcase_19 AC 484 ms
96,860 KB
testcase_20 AC 313 ms
91,640 KB
testcase_21 AC 217 ms
81,156 KB
testcase_22 AC 743 ms
115,824 KB
testcase_23 AC 307 ms
86,624 KB
testcase_24 AC 202 ms
81,304 KB
testcase_25 AC 105 ms
77,296 KB
testcase_26 AC 515 ms
103,028 KB
testcase_27 AC 648 ms
110,140 KB
testcase_28 AC 614 ms
105,424 KB
testcase_29 AC 287 ms
85,052 KB
testcase_30 AC 309 ms
89,332 KB
testcase_31 AC 324 ms
87,376 KB
testcase_32 AC 961 ms
131,016 KB
testcase_33 AC 36 ms
52,352 KB
testcase_34 AC 36 ms
52,864 KB
testcase_35 AC 37 ms
52,736 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