結果
| 問題 |
No.2731 Two Colors
|
| コンテスト | |
| ユーザー |
sasa8uyauya
|
| 提出日時 | 2024-04-19 22:29:41 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,123 bytes |
| コンパイル時間 | 2,007 ms |
| コンパイル使用メモリ | 81,792 KB |
| 実行使用メモリ | 132,184 KB |
| 最終ジャッジ日時 | 2024-10-11 16:03:33 |
| 合計ジャッジ時間 | 31,103 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 TLE * 3 |
ソースコード
h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
v=[[0]*w for i in range(h)]
v[0][0]=1
v[h-1][w-1]=2
from heapq import heappush,heappop
q1=[]
heappush(q1,(a[1][0],1,0))
heappush(q1,(a[0][1],0,1))
q2=[]
heappush(q2,(a[h-2][w-1],h-2,w-1))
heappush(q2,(a[h-1][w-2],h-1,w-2))
for i in range(1,h*w+1):
if i%2:
while len(q1)>0 and v[q1[0][1]][q1[0][2]]!=0:
heappop(q1)
if len(q1)==0:
print(i-1)
exit()
z,x,y=heappop(q1)
v[x][y]=1
dx,dy=1,0
for _ in range(4):
xx,yy=x+dx,y+dy
dx,dy=-dy,dx
if 0<=xx<h and 0<=yy<w:
if v[xx][yy]==0:
heappush(q1,(a[xx][yy],xx,yy))
if v[xx][yy]==2:
print(i)
exit()
else:
while len(q2)>0 and v[q2[0][1]][q2[0][2]]!=0:
heappop(q2)
if len(q2)==0:
print(i-1)
exit()
z,x,y=heappop(q2)
v[x][y]=2
dx,dy=1,0
for _ in range(4):
xx,yy=x+dx,y+dy
dx,dy=-dy,dx
if 0<=xx<h and 0<=yy<w:
if v[xx][yy]==0:
heappush(q2,(a[xx][yy],xx,yy))
if v[xx][yy]==1:
print(i)
exit()
sasa8uyauya