結果

問題 No.2928 Gridpath
ユーザー momoyuu
提出日時 2024-10-13 18:14:37
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,070 bytes
コンパイル時間 1,036 ms
コンパイル使用メモリ 98,080 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 18:14:55
合計ジャッジ時間 1,827 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int h,w;
    cin>>h>>w;
    int si,sj,gi,gj;
    cin>>si>>sj>>gi>>gj;
    si--;gi--;sj--;gj--;
    int ans = 0;
    vector<vector<int>> cnt(h,vector<int>(w,0));
    int dx[] = {1,-1,0,0};
    int dy[] = {0,0,1,-1};
    auto dfs = [&](auto dfs,int x,int y) -> void {
        int now = 0;
        for(int k = 0;k<4;k++){
            int nx = x + dx[k];
            int ny = y + dy[k];
            if(nx<0||nx>=h||ny<0||ny>=w) continue;
            if(cnt[nx][ny]) now++;
        }
        if(now>=2) return;
        if(x==gi&&y==gj){
            ans++;
            return;
        }
        cnt[x][y]++;
        for(int k = 0;k<4;k++){
            int nx = x + dx[k];
            int ny = y + dy[k];
            if(nx<0||nx>=h||ny<0||ny>=w) continue;
            if(cnt[nx][ny]) continue;
            dfs(dfs,nx,ny);
        }
        cnt[x][y]--;
    };
    dfs(dfs,si,sj);
    cout<<ans<<endl;
}
0