結果
問題 |
No.2731 Two Colors
|
ユーザー |
![]() |
提出日時 | 2024-04-20 10:49:36 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,167 bytes |
コンパイル時間 | 211 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 305,288 KB |
最終ジャッジ日時 | 2024-10-12 06:25:25 |
合計ジャッジ時間 | 9,836 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | TLE * 2 -- * 31 |
ソースコード
from heapq import heapify,heappop,heappush h,w=map(int,input().split()) a=[list(map(int,input().split())) for i in range(h)] colored0=set([(0,0)]) colored1=set([(h-1,w-1)]) ad0=set([(0,0),(0,1),(1,0)]) ad1=set([(h-1,w-1),(h-2,w-1),(h-1,w-2)]) ad=[ad0,ad1] que0=[] que1=[] heappush(que0,(a[0][1],0,1)) heappush(que0,(a[1][0],1,0)) heappush(que1,(a[h-1][w-2],h-1,w-2)) heappush(que1,(a[h-2][w-1],h-2,w-1)) que=[que0,que1] colored=[colored0,colored1] walk=[ (1,0), (-1,0), (0,1), (0,-1), ] def inside(y,x): return 0<=y<h and 0<=x<w for i in range(h*w): t_que=que[i%2] t_colored=colored[i%2] o_colored=colored[(i%2)^1] t_ad=ad[i%2] while t_que: _,y,x=heappop(t_que) if (y,x) not in t_colored: break t_colored.add((y,x)) # 隣がo_coloredで塗られている場合exit for iy,ix in walk: ny,nx=iy+y,ix+x if (ny,nx) in o_colored: print(i+1) exit() for iy,ix in walk: ny,nx=iy+y,ix+x if inside(ny,nx): if not (ny,nx) in t_ad: t_ad.add((ny,nx)) heappush(t_que,(a[ny][nx],ny,nx))