結果
問題 | No.2928 Gridpath |
ユーザー |
![]() |
提出日時 | 2024-10-12 15:50:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 124 ms / 2,000 ms |
コード長 | 673 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 76,880 KB |
最終ジャッジ日時 | 2024-10-12 15:50:59 |
合計ジャッジ時間 | 2,354 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
H,W=map(int,input().split()) sx,sy=map(int,input().split()) gx,gy=map(int,input().split()) sx-=1 sy-=1 gx-=1 gy-=1 def dfs(px,py): global a if (px,py)==(gx,gy): a+=1 else: for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]: tx,ty=px+dx,py+dy if 0<=tx<H and 0<=ty<W and v[tx][ty]==0: f=1 for dx2,dy2 in [(1,0),(0,1),(-1,0),(0,-1)]: ux,uy=tx+dx2,ty+dy2 if 0<=ux<H and 0<=uy<W and v[ux][uy]!=0: if v[ux][uy]<v[px][py]: f=0 break if f: v[tx][ty]=v[px][py]+1 dfs(tx,ty) v[px][py]=0 return a=0 v=[[0]*W for i in range(H)] v[sx][sy]=1 dfs(sx,sy) print(a)