結果
| 問題 |
No.2731 Two Colors
|
| コンテスト | |
| ユーザー |
rarpipipi
|
| 提出日時 | 2024-04-20 10:47:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,039 bytes |
| コンパイル時間 | 387 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 266,316 KB |
| 最終ジャッジ日時 | 2024-10-12 06:22:03 |
| 合計ジャッジ時間 | 9,520 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 32 |
ソースコード
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)])
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]
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_colored:
heappush(t_que,(a[ny][nx],ny,nx))
rarpipipi