結果

問題 No.2928 Gridpath
ユーザー D M
提出日時 2025-02-07 16:37:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 701 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 83,032 KB
実行使用メモリ 76,564 KB
最終ジャッジ日時 2025-02-07 16:37:19
合計ジャッジ時間 3,007 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w=map(int,input().split())
int1=lambda x:int(x)-1
si,sj=map(int1,input().split())
gi,gj=map(int1,input().split())
F=[[0]*w for _ in range(h)]
ans=0
def dfs(x,y):
    global ans
    if (x,y)==(gi,gj):
        ans+=1
    else:
        F[x][y]=1
        for i,j in [(0,1),(0,-1),(1,0),(-1,0)]:
            nx,ny=x+i,y+j
            if 0<=nx<h and 0<=ny<w and F[nx][ny]==0:
                stc=0
                for ii, jj in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
                    nnx, nny = nx + ii, ny + jj
                    if 0<=nnx<h and 0<=nny<w and F[nnx][nny]==1:
                        stc+=1
                if stc==1:
                    dfs(nx,ny)
        F[x][y]=0
dfs(si,sj)
print(ans)
0