結果
| 問題 |
No.2928 Gridpath
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-19 20:59:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 1,047 bytes |
| コンパイル時間 | 1,955 ms |
| コンパイル使用メモリ | 199,780 KB |
| 最終ジャッジ日時 | 2025-02-24 21:43:23 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int MOD=998244353;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,l,r) for(int i=(l);i<(int)(r);i++)
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
array<int,2> S,G;
int dfs(vector<vector<bool>>& a,int h,int w,const int& H,const int& W){
if(h==G[0]&&w==G[1])return 1;
auto bound_ok=[H,W](int x,int y){
return x>=0&&x<H&&y>=0&&y<W;
};
int ret=0;
rep(k,4){
int h2=h+dx[k],w2=w+dy[k];
if(bound_ok(h2,w2)&&!a[h2][w2]){
int cnt=0;
rep(i,4){
int h3=h2+dx[i],w3=w2+dy[i];
if(bound_ok(h3,w3)&&a[h3][w3])cnt++;
}
if(cnt==1){
a[h2][w2]=1;
ret+=dfs(a,h2,w2,H,W);
a[h2][w2]=0;
}
}
}
return ret;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int H,W;
cin>>H>>W;
cin>>S[0]>>S[1];
cin>>G[0]>>G[1];
S[0]--,S[1]--,G[0]--,G[1]--;
vector A(H,vector(W,false));
A[S[0]][S[1]]=1;
cout<<dfs(A,S[0],S[1],H,W)<<'\n';
}