結果
問題 | No.2928 Gridpath |
ユーザー |
![]() |
提出日時 | 2024-10-18 12:07:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 156 ms / 2,000 ms |
コード長 | 962 bytes |
コンパイル時間 | 539 ms |
コンパイル使用メモリ | 82,232 KB |
実行使用メモリ | 78,020 KB |
最終ジャッジ日時 | 2024-10-18 12:07:56 |
合計ジャッジ時間 | 3,279 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
from collections import dequeimport syssys.setrecursionlimit(1 << 20)H,W=map(int,input().split())Si,Sj=map(int,input().split())Gi,Gj=map(int,input().split())d=[[1,0],[0,1],[-1,0],[0,-1]]global ansans=0seen=[[False for j in range(W)] for i in range(H)]def dfs(x1,y1):global ansseen[x1][y1]=True#print(seen[0])#print(seen[1])#print("###")if x1==Gi-1 and y1==Gj-1:ans += 1seen[x1][y1] = False#print("#")returnfor x,y in d:x2=x1+xy2=y1+yif not (0<=y2<W):continueif not (0<=x2<H):continueif seen[x2][y2]:continuecnt=0for xx,yy in d:xt=x2+xxyt=y2+yyif not (0<=yt<W):continueif not (0<=xt<H):continueif seen[xt][yt]:cnt +=1if cnt>1:continueelse:dfs(x2,y2)seen[x1][y1] = Falsedfs(Si-1,Sj-1)print(ans)