結果

問題 No.2928 Gridpath
コンテスト
ユーザー 回転
提出日時 2026-07-22 19:10:01
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 113 ms / 2,000 ms
+ 777µs
コード長 997 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 716 ms
コンパイル使用メモリ 95,980 KB
実行使用メモリ 84,932 KB
最終ジャッジ日時 2026-07-22 19:10:06
合計ジャッジ時間 3,840 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

H,W = list(map(int,input().split()))
sy,sx = list(map(lambda x:int(x)-1,input().split()))
gy,gx = list(map(lambda x:int(x)-1,input().split()))

dy = [-1,1,0,0]
dx = [0,0,-1,1]
visited = [[False for _ in range(W)] for _ in range(H)]
ans = 0
def f(y,x):
    if(y == gy and x == gx):
        global ans
        ans += 1
        return

    visited[y][x] = True

    for i in range(4):
        next_y = y + dy[i]
        next_x = x + dx[i]
        if(next_y < 0 or H <= next_y):continue
        if(next_x < 0 or W <= next_x):continue
        if(visited[next_y][next_x]):continue
        
        count = 0
        for j in range(4):
            next_next_y = next_y + dy[j]
            next_next_x = next_x + dx[j]
            if(next_next_y < 0 or H <= next_next_y):continue
            if(next_next_x < 0 or W <= next_next_x):continue
            count += visited[next_next_y][next_next_x]

        if(count >= 2):continue
        f(next_y,next_x)

    visited[y][x] = False    

f(sy,sx)
print(ans)
0