結果

問題 No.2928 Gridpath
ユーザー rlangevin
提出日時 2024-11-05 08:54:51
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 933 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-11-05 08:54:53
合計ジャッジ時間 2,693 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
def check(px, py):
    cnt = 0
    for k in range(4):
        x, y = px + dx[k], py + dy[k]
        if x < 0 or x > H - 1 or y < 0 or y > W - 1:
            continue
        cnt += seen[x][y]
    return cnt

def dfs(x, y):
    global ans
    if x == gx and y == gy:
        ans += 1
        return 
    for k in range(4):
        nx, ny = x + dx[k], y + dy[k]
        if nx < 0 or nx > H - 1 or ny < 0 or ny > W - 1:
            continue
        if seen[nx][ny]:
            continue
        if check(nx, ny) >= 2:
            continue
        seen[nx][ny] = 1
        dfs(nx, ny)
        seen[nx][ny] = 0
    return 

H, W = map(int, input().split())
sx, sy = map(int, input().split())
gx, gy = map(int, input().split())
seen = [[0] * W for _ in range(H)]

ans = 0
sx, sy, gx, gy = sx - 1, sy - 1, gx - 1, gy - 1
seen[sx][sy] = 1
dfs(sx, sy)

print(ans)
0