結果
問題 |
No.2731 Two Colors
|
ユーザー |
![]() |
提出日時 | 2024-04-19 22:07:19 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,190 bytes |
コンパイル時間 | 586 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 139,912 KB |
最終ジャッジ日時 | 2024-10-11 15:22:18 |
合計ジャッジ時間 | 9,840 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | TLE * 1 -- * 32 |
ソースコード
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)] 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: heappush(Q1,(A[z][w],z,w)) 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: heappush(Q2,(A[z][w],z,w)) if USE[z][w]==1: flag=1 print(tt)