結果
| 問題 |
No.124 門松列(3)
|
| ユーザー |
yuyyuyu
|
| 提出日時 | 2015-08-04 18:33:56 |
| 言語 | Python2 (2.7.18) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 659 bytes |
| コンパイル時間 | 42 ms |
| コンパイル使用メモリ | 7,040 KB |
| 実行使用メモリ | 35,876 KB |
| 最終ジャッジ日時 | 2024-07-18 01:18:14 |
| 合計ジャッジ時間 | 12,478 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | TLE * 1 -- * 25 |
ソースコード
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,0]]
while que:
[x,y,bfr,count]=que.pop(0)
cur=M[y][x]
if x==W-1 and y==H-1:
print count
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(bfr,cur,aft):continue
que.append([nx,ny,cur,count+1])
print -1
yuyyuyu