結果

問題 No.2731 Two Colors
ユーザー titiatitia
提出日時 2024-04-19 22:13:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,475 ms / 3,000 ms
コード長 1,396 bytes
コンパイル時間 783 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 129,316 KB
最終ジャッジ日時 2024-04-19 22:14:06
合計ジャッジ時間 18,251 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,449 ms
128,960 KB
testcase_01 AC 1,474 ms
129,316 KB
testcase_02 AC 1,475 ms
129,004 KB
testcase_03 AC 121 ms
77,480 KB
testcase_04 AC 153 ms
79,608 KB
testcase_05 AC 155 ms
78,372 KB
testcase_06 AC 250 ms
83,816 KB
testcase_07 AC 211 ms
85,072 KB
testcase_08 AC 141 ms
78,080 KB
testcase_09 AC 427 ms
109,700 KB
testcase_10 AC 134 ms
77,196 KB
testcase_11 AC 796 ms
114,872 KB
testcase_12 AC 415 ms
109,644 KB
testcase_13 AC 649 ms
108,968 KB
testcase_14 AC 296 ms
91,560 KB
testcase_15 AC 147 ms
77,696 KB
testcase_16 AC 354 ms
91,680 KB
testcase_17 AC 392 ms
96,580 KB
testcase_18 AC 181 ms
79,976 KB
testcase_19 AC 400 ms
91,696 KB
testcase_20 AC 274 ms
96,840 KB
testcase_21 AC 187 ms
80,736 KB
testcase_22 AC 560 ms
112,704 KB
testcase_23 AC 242 ms
85,280 KB
testcase_24 AC 183 ms
80,460 KB
testcase_25 AC 108 ms
76,600 KB
testcase_26 AC 412 ms
104,060 KB
testcase_27 AC 492 ms
111,636 KB
testcase_28 AC 462 ms
100,344 KB
testcase_29 AC 252 ms
83,324 KB
testcase_30 AC 270 ms
88,796 KB
testcase_31 AC 264 ms
85,116 KB
testcase_32 AC 768 ms
123,508 KB
testcase_33 AC 40 ms
52,608 KB
testcase_34 AC 41 ms
52,352 KB
testcase_35 AC 38 ms
52,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from heapq import heappop,heappush,heapify

H,W=map(int,input().split())

A=[list(map(int,input().split())) for i in range(H)]

Q1=[]
Q2=[]
USE=[[0]*W for i in range(H)]
USE2=[[0]*W for i in range(H)]

USE3=[[0]*W for i in range(H)]
USE4=[[0]*W for i in range(H)]


Q1.append((A[0][1],0,1))
Q1.append((A[1][0],1,0))

Q2.append((A[H-1][W-2],H-1,W-2))
Q2.append((A[H-2][W-1],H-2,W-1))

heapify(Q1)
heapify(Q2)

USE[0][0]=1
USE2[H-1][W-1]=1
flag=0
for tt in range(10**9):
    if flag==1:
        break
    if tt%2==0:
        while True:
            _,x,y=heappop(Q1)
            if USE[x][y]==1:
                continue
            USE[x][y]=1
            break

        for z,w in [(x+1,y),(x-1,y),(x,y-1),(x,y+1)]:
            if 0<=z<H and 0<=w<W:
                if USE3[z][w]==0:
                    heappush(Q1,(A[z][w],z,w))
                    USE3[z][w]=1
                if USE2[z][w]==1:
                    flag=1
    else:
        while True:
            _,x,y=heappop(Q2)
            if USE2[x][y]==1:
                continue
            USE2[x][y]=1
            break


        for z,w in [(x+1,y),(x-1,y),(x,y-1),(x,y+1)]:
            if 0<=z<H and 0<=w<W:
                if USE4[z][w]==0:
                    heappush(Q2,(A[z][w],z,w))
                    USE4[z][w]=1
                if USE[z][w]==1:
                    flag=1
print(tt)
0