結果
| 問題 |
No.124 門松列(3)
|
| コンテスト | |
| ユーザー |
Tawara
|
| 提出日時 | 2015-12-31 02:00:09 |
| 言語 | Python2 (2.7.18) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 604 bytes |
| コンパイル時間 | 503 ms |
| コンパイル使用メモリ | 7,040 KB |
| 実行使用メモリ | 134,304 KB |
| 最終ジャッジ日時 | 2024-09-19 08:54:16 |
| 合計ジャッジ時間 | 12,781 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | TLE * 1 -- * 25 |
ソースコード
from collections import defaultdict as D 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 xrange(H)];dxy=((1,0),(0,1),(-1,0),(0,-1)) C=[[D(lambda:W*H+1)for i in xrange(W)]for i in xrange(H)];Q=[] for x,y in dxy[:2]:A=(M[0][0],M[y][x]);C[y][x][A]=1;Q+=[(1,(x,y),A)] while Q: c,h,A=heappop(Q) if h==G:print c;break for dx,dy in dxy: nx=h[0]+dx;ny=h[1]+dy if 0<=nx<W and 0<=ny<H: A2=M[ny][nx];nA=(A[1],A2);nc=c+1 if(A[0]-A[1])*(A[1]-A2)<0 and A[0]!=A2 and nc<C[ny][nx][A]: heappush(Q,(nc,(nx,ny),nA));C[ny][nx][nA]=nc else:print -1
Tawara