結果
| 問題 |
No.124 門松列(3)
|
| ユーザー |
yuyyuyu
|
| 提出日時 | 2015-08-04 18:52:53 |
| 言語 | PyPy2 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 104 ms / 5,000 ms |
| コード長 | 810 bytes |
| コンパイル時間 | 184 ms |
| コンパイル使用メモリ | 76,540 KB |
| 実行使用メモリ | 79,284 KB |
| 最終ジャッジ日時 | 2024-07-18 01:18:18 |
| 合計ジャッジ時間 | 3,321 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
dxdy=zip([-1,0,1,0],[0,1,0,-1])
def kadomatsu(a,b,c):
if a==0 or b==0:
return True
else:
if (a!=b and b!=c and c!=a) and not (a<b<c or a>b>c):
return True
else:
return False
W,H=map(int,raw_input().split())
M=[map(int,raw_input().split()) for _ in xrange(H)]
que=[[0,0,0]]
cost=[[[-1]*W for _ in xrange(H)] for i in xrange(10)]
cost[0][0][0]=0
while que:
[bef,x,y]=que.pop(0)
cur=M[y][x]
if x==W-1 and y==H-1:
print cost[bef][y][x]
exit()
for dx,dy in dxdy:
nx,ny=x+dx,y+dy
if not(0<=nx<W and 0<=ny<H):continue
aft=M[ny][nx]
if not kadomatsu(bef,cur,aft):continue
if cost[cur][ny][nx]!=-1:continue
cost[cur][ny][nx]=cost[bef][y][x]+1
que.append([cur,nx,ny])
print -1
yuyyuyu