結果
問題 | No.124 門松列(3) |
ユーザー |
![]() |
提出日時 | 2015-07-30 14:29:58 |
言語 | PyPy2 (7.3.15) |
結果 |
AC
|
実行時間 | 127 ms / 5,000 ms |
コード長 | 746 bytes |
コンパイル時間 | 416 ms |
コンパイル使用メモリ | 77,096 KB |
実行使用メモリ | 79,524 KB |
最終ジャッジ日時 | 2024-07-17 22:36:02 |
合計ジャッジ時間 | 4,131 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
def isKadomatsu(a,b,c):if a == 0 or b == 0: return Truereturn b < a < c or b < c < a or a < c < b or c < a < bdxdy=zip([-1,0,1,0],[0,1,0,-1])W,H=map(int,raw_input().split())M=[map(int,raw_input().split()) for i in xrange(H)]que=[[0,0,0]]cost=[[[-1]*W for _ in xrange(H)] for i in xrange(10)]cost[0][0][0]=0while que:w,h,bef=que.pop(0)if w==W-1 and h==H-1:print cost[bef][h][w]breakcur=M[h][w]for dx,dy in dxdy:nw,nh=w+dx,h+dyif not (0<=nw<W and 0<=nh<H):continueaft=M[nh][nw]if not (isKadomatsu(bef,cur,aft)):continueif cost[cur][nh][nw]!=-1:continuecost[cur][nh][nw]=cost[bef][h][w]+1que.append([nw,nh,cur])else:print -1