結果
| 問題 | No.2928 Gridpath | 
| コンテスト | |
| ユーザー |  srjywrdnprkt | 
| 提出日時 | 2024-10-15 00:58:43 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 2,000 ms | 
| コード長 | 1,191 bytes | 
| コンパイル時間 | 2,069 ms | 
| コンパイル使用メモリ | 199,720 KB | 
| 最終ジャッジ日時 | 2025-02-24 19:40:29 | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 20 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int ans=0, H, W, sx, sy, gx, gy;
    cin >> H >> W;
    cin >> sx >> sy;
    cin >> gx >> gy;
    sx--; sy--; gx--; gy--;
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};
    auto f=[&](int h, int w){
        return 0 <= h && h < H && 0 <= w && w < W;
    };
    vector used(H, vector<bool>(W));
    auto dfs=[&](auto self, int i, int j)->void{
        if (i == gx && j == gy){
            ans++;
            return;
        }
        used[i][j] = 1;
        int ni, nj, ni2, nj2;
        for (int k=0; k<4; k++){
            ni = i+dx[k]; nj = j+dy[k];
            if (!f(ni, nj)) continue;
            if (used[ni][nj]) continue;
            bool ok=1;
            for (int l=0; l<4; l++){
                ni2 = ni+dx[l]; nj2 = nj+dy[l];
                if (!f(ni2, nj2)) continue;
                if (ni2 == i && nj2 == j) continue;
                if (used[ni2][nj2]) ok=0;
            }
            if (ok) self(self, ni, nj);
        }
        used[i][j] = 0;
    };
    dfs(dfs, sx, sy);
    cout << ans << endl;
    return 0;
}
            
            
            
        