結果
| 問題 |
No.2928 Gridpath
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-12 15:21:33 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,160 bytes |
| コンパイル時間 | 1,976 ms |
| コンパイル使用メモリ | 200,600 KB |
| 最終ジャッジ日時 | 2025-02-24 18:01:14 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int h, w, sy, sx, ty, tx;
cin >> h >> w;
cin >> sy >> sx >> ty >> tx;
sy--, sx--, ty--, tx--;
int ans = 0;
vector<pair<int,int>> dir = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
vector B(h, vector<bool>(w));
auto dfs = [&](auto dfs, int y, int x, int py, int px) -> void {
for(auto [ny, nx] : dir){
ny += y, nx += x;
if(ny == py && nx == px) continue;
if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
if(B[ny][nx]) return;
}
if(y == ty && x == tx){
ans++;
return;
}
B[y][x] = true;
for(auto [ny, nx] : dir){
ny += y, nx += x;
//cerr << y << " " << x << " " << ny << " " << nx << " " << py << " " << px << "\n";
if(ny == py && nx == px) continue;
if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
dfs(dfs, ny, nx, y, x);
}
B[y][x] = false;
};
dfs(dfs, sy, sx, -1, -1);
cout << ans << '\n';
}