結果
| 問題 | No.2928 Gridpath | 
| コンテスト | |
| ユーザー | 👑 | 
| 提出日時 | 2024-09-13 01:03:31 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 97 ms / 2,000 ms | 
| コード長 | 1,106 bytes | 
| コンパイル時間 | 448 ms | 
| コンパイル使用メモリ | 82,588 KB | 
| 実行使用メモリ | 76,740 KB | 
| 最終ジャッジ日時 | 2024-09-13 01:03:34 | 
| 合計ジャッジ時間 | 3,135 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 20 | 
ソースコード
import sys
sys.setrecursionlimit(10**5)
ways = set([(0, 1), (0, -1), (1, 0), (-1, 0)])
H, W = map(int, input().split())
S_i, S_j = map(lambda x: int(x) - 1, input().split())
G_i, G_j = map(lambda x: int(x) - 1, input().split())
grid = [[0 for _ in range(W)] for _ in range(H)]
ans = 0
def dfs(now_i, now_j):
    global ans
    if now_i == G_i and now_j == G_j:
        ans += 1
        return
    grid[now_i][now_j] += 1
    for di, dj in ways:
        next_i, next_j = now_i + di, now_j + dj
        if next_i < 0 or next_i >= H or next_j < 0 or next_j >= W:
            continue
        grid[next_i][next_j] += 1
    for di, dj in ways:
        next_i, next_j = now_i + di, now_j + dj
        if next_i < 0 or next_i >= H or next_j < 0 or next_j >= W:
            continue
        if grid[next_i][next_j] <= 1:
            dfs(next_i, next_j)
    grid[now_i][now_j] -= 1
    for di, dj in ways:
        next_i, next_j = now_i + di, now_j + dj
        if next_i < 0 or next_i >= H or next_j < 0 or next_j >= W:
            continue
        grid[next_i][next_j] -= 1
dfs(S_i, S_j)
print(ans)
            
            
            
        