結果
| 問題 |
No.2928 Gridpath
|
| コンテスト | |
| ユーザー |
k82b
|
| 提出日時 | 2024-10-12 15:33:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 2,000 ms |
| コード長 | 857 bytes |
| コンパイル時間 | 878 ms |
| コンパイル使用メモリ | 76,808 KB |
| 最終ジャッジ日時 | 2025-02-24 18:05:25 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <iostream>
#include <vector>
using Int = long long;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
int H, W;
std::cin >> H >> W;
int Si, Sj;
std::cin >> Si >> Sj;
--Si;
--Sj;
int Gi, Gj;
std::cin >> Gi >> Gj;
--Gi;
--Gj;
int ans = 0;
std::vector vis(H, std::vector(W, false));
auto dfs = [&](auto dfs, int x, int y) {
if (x < 0 || y < 0 || x >= H || y >= W ||vis[x][y]) return;
int cnt = 0;
for (int i = 0; i < 4; ++i) {
int xx = x + dx[i];
int yy = y + dy[i];
if (xx < 0 || yy < 0 || xx >= H || yy >= W) continue;
if (vis[xx][yy]) {
++cnt;
}
}
if (cnt > 1) return;
if (x == Gi && y == Gj) {
++ans;
return;
}
vis[x][y] = true;
for (int i = 0; i < 4; ++i) {
dfs(dfs, x + dx[i], y + dy[i]);
}
vis[x][y] = false;
};
dfs(dfs, Si, Sj);
std::cout << ans << std::endl;
}
k82b