結果
| 問題 | No.2731 Two Colors |
| コンテスト | |
| ユーザー |
nikoro256
|
| 提出日時 | 2024-04-19 22:04:46 |
| 言語 | PyPy3 (8.0.0 + ACL) |
| 結果 |
TLE
不安定
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 697 bytes |
| 記録 | |
| コンパイル時間 | 1,593 ms |
| コンパイル使用メモリ | 64,228 KB |
| 実行使用メモリ | 131,932 KB |
| 最終ジャッジ日時 | 2026-10-16 22:22:05 |
| 合計ジャッジ時間 | 31,364 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 TLE * 1 |
ソースコード
import heapq
H,W=map(int,input().split())
A=[]
for _ in range(H):
A.append(list(map(int,input().split())))
hq=[[] for _ in range(2)]
heapq.heappush(hq[0],(A[0][0],0,0))
heapq.heappush(hq[1],(A[-1][-1],H-1,W-1))
use=[[-1]*W for _ in range(H)]
d=[[1,0],[-1,0],[0,1],[0,-1]]
count=0
while True:
p,x,y=heapq.heappop(hq[count%2])
if use[x][y]!=-1:
continue
use[x][y]=count%2
for x_d,y_d in d:
x_m=x+x_d
y_m=y+y_d
if 0<=x_m<H and 0<=y_m<W :
if use[x_m][y_m]==1-count%2:
print(count-1)
exit(0)
elif use[x_m][y_m]==-1:
heapq.heappush(hq[count%2],(A[x_m][y_m],x_m,y_m))
count+=1
nikoro256