結果
| 問題 |
No.2928 Gridpath
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-12 15:24:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,075 bytes |
| コンパイル時間 | 2,025 ms |
| コンパイル使用メモリ | 203,732 KB |
| 最終ジャッジ日時 | 2025-02-24 18:02:33 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int H,W; cin >> H >> W;
vector<vector<bool>> already(H,vector<bool>(W));
int sx,sy,gx,gy; cin >> sx >> sy >> gx >> gy;
sx--; sy--; gx--; gy--;
int answer = 0;
vector<pair<int,int>> dxy = {{-1,0},{0,1},{1,0},{0,-1}};
auto dfs = [&](auto dfs,int x,int y,int bx,int by) -> void {
for(auto [dx,dy] : dxy){
int nx = x+dx,ny = y+dy;
if(nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
if(bx == nx && by == ny) continue;
if(already.at(nx).at(ny)) return;
}
if(x == gx && y == gy){answer++; return;}
already.at(x).at(y) = true;
for(auto [dx,dy] : dxy){
int nx = x+dx,ny = y+dy;
if(nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
if(already.at(nx).at(ny)) continue;
dfs(dfs,nx,ny,x,y);
}
already.at(x).at(y) = false;
};
dfs(dfs,sx,sy,-1,-1);
cout << answer << endl;
}