結果

問題 No.2731 Two Colors
ユーザー anonymouslyanonymously
提出日時 2024-04-19 22:23:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,262 ms / 3,000 ms
コード長 831 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 123,996 KB
最終ジャッジ日時 2024-04-19 22:23:53
合計ジャッジ時間 15,170 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,260 ms
123,620 KB
testcase_01 AC 1,262 ms
123,984 KB
testcase_02 AC 1,236 ms
123,996 KB
testcase_03 AC 104 ms
76,712 KB
testcase_04 AC 145 ms
78,356 KB
testcase_05 AC 152 ms
78,632 KB
testcase_06 AC 209 ms
83,876 KB
testcase_07 AC 186 ms
82,628 KB
testcase_08 AC 123 ms
77,580 KB
testcase_09 AC 351 ms
100,540 KB
testcase_10 AC 120 ms
76,368 KB
testcase_11 AC 578 ms
121,012 KB
testcase_12 AC 335 ms
100,480 KB
testcase_13 AC 533 ms
113,916 KB
testcase_14 AC 237 ms
87,876 KB
testcase_15 AC 142 ms
77,668 KB
testcase_16 AC 298 ms
91,924 KB
testcase_17 AC 308 ms
95,216 KB
testcase_18 AC 172 ms
79,100 KB
testcase_19 AC 338 ms
94,328 KB
testcase_20 AC 252 ms
89,676 KB
testcase_21 AC 177 ms
80,136 KB
testcase_22 AC 424 ms
109,144 KB
testcase_23 AC 233 ms
84,584 KB
testcase_24 AC 179 ms
80,508 KB
testcase_25 AC 113 ms
76,928 KB
testcase_26 AC 363 ms
99,524 KB
testcase_27 AC 411 ms
106,100 KB
testcase_28 AC 348 ms
100,880 KB
testcase_29 AC 200 ms
83,920 KB
testcase_30 AC 245 ms
87,284 KB
testcase_31 AC 246 ms
86,244 KB
testcase_32 AC 569 ms
122,596 KB
testcase_33 AC 37 ms
52,736 KB
testcase_34 AC 39 ms
52,608 KB
testcase_35 AC 38 ms
52,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

D=[[1,0],[0,1],[-1,0],[0,-1]]

H,W=map(int,input().split())
A=[]
for i in range(H):
    A.append([int(_) for _ in input().split()])

C=[[None for j in range(W)] for i in range(H)]

Q=[[(A[H-1][W-1],(H-1,W-1))],[(A[0][0],(0,0))]]
heapq.heapify(Q[1])
heapq.heapify(Q[0])

step = -2
while True:
    step += 1
    k = step%2
    while True:
        _, p = heapq.heappop(Q[k])
        Y, X = p
        if C[Y][X] is None:
            break
    C[Y][X]=k
    f = False
    for d in D:
        y = Y + d[0]
        x = X + d[1]
        if 0<=y<H and 0<=x<W:
            if C[y][x]==1-k:
                f = True
                break
            if C[y][x] is None:
                heapq.heappush(Q[k], (A[y][x],(y,x)))
    if f:
        break
print(step)
'''
for c in C:
    print(*[' ' if _ is None else _ for _ in c])
'''
0