結果
| 問題 | No.124 門松列(3) |
| コンテスト | |
| ユーザー |
Tawara
|
| 提出日時 | 2015-12-31 02:29:53 |
| 言語 | PyPy2 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 119 ms / 5,000 ms |
| コード長 | 537 bytes |
| 記録 | |
| コンパイル時間 | 146 ms |
| コンパイル使用メモリ | 76,868 KB |
| 最終ジャッジ日時 | 2025-12-03 18:59:07 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
from heapq import heappop,heappush I=lambda:map(int,raw_input().split());W,H=I();G=(W-1,H-1) M=[I()for i in range(H)];dxy=((1,0),(0,1),(-1,0),(0,-1)) C=[[[W*H+1]*10 for i in range(W)]for i in range(H)];Q=[] for x,y in dxy[:2]:C[y][x][M[0][0]]=1;Q+=[(1,(x,y),M[0][0])] while Q: c,h,b=heappop(Q) if h==G:print c;break t=M[h[1]][h[0]];nc=c+1 for dx,dy in dxy: nx=h[0]+dx;ny=h[1]+dy if 0<=nx<W and 0<=ny<H: n=M[ny][nx] if(n-t)*(t-b)<0 and b!=n and nc<C[ny][nx][t]: heappush(Q,(nc,(nx,ny),t));C[ny][nx][t]=nc else: print -1
Tawara