結果
| 問題 |
No.2731 Two Colors
|
| コンテスト | |
| ユーザー |
vwxyz
|
| 提出日時 | 2024-08-09 05:17:19 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 955 bytes |
| コンパイル時間 | 338 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 88,888 KB |
| 最終ジャッジ日時 | 2024-08-09 05:17:30 |
| 合計ジャッジ時間 | 10,095 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 32 |
ソースコード
import heapq
H,W=map(int,input().split())
A=[list(map(int,input().split())) for h in range(H)]
color=[[None]*W for h in range(H)]
queue=[[(A[0][1],0,1),(A[1][0],1,0)],[(A[H-1][W-2],H-1,W-2),(A[H-2][W-1],H-2,W-1)]]
color[0][0]=0
color[H-1][W-1]=1
heapq.heapify(queue[0])
heapq.heapify(queue[1])
seen=[[[False]*W for h in range(H)] for c in range(2)]
seen[0][0][1]=1
seen[0][1][0]=1
seen[1][H-1][W-2]=1
seen[1][H-2][W-1]=1
ans=0
while True:
c=ans%2
a,h,w=heapq.heappop(queue[c])
ans+=1
color[h][w]=c
skip=False
for dh,dw in ((0,1),(1,0),(0,-1),(-1,0)):
if 0<=h+dh<H and 0<=w+dw<W:
if color[h+dh][w+dw]==None:
if seen[c][h+dh][w+dw]:
continue
heapq.heappush(queue[c],(A[h+dh][w+dw],h+dh,w+dw))
seen[c][h+dh][w+dw]=True
else:
if color[h+dh][w+dw]!=c:
skip=True
if skip:
break
print(ans)
vwxyz