結果
| 問題 |
No.2928 Gridpath
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-17 23:12:28 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,747 bytes |
| コンパイル時間 | 4,406 ms |
| コンパイル使用メモリ | 284,908 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 23:12:33 |
| 合計ジャッジ時間 | 5,394 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const ll LINF = 3001001001001001001;
const int MOD = 998244353;
const string Yes = "Yes";
const string No = "No";
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> istream &operator>>(istream &is, vector<T> &v) {for (T &in : v)is >> in;return is;}
vector<pair<int,int>> dir = {{0,1},{0,-1},{1,0},{-1,0},};
// #include <ext/pb_ds/assoc_container.hpp>
// template<typename T>
// using ordered_set = __gnu_pbds::tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main() {
int h,w;cin>>h>>w;
int si,sj,gi,gj;cin>>si>>sj>>gi>>gj;
si--,sj--,gi--,gj--;
int ans = 0;
vector ng(h,vector(w,false));
ng.at(si).at(sj) = true;
auto in = [&](unsigned x,unsigned y) -> bool {
return x<h&&y<w;
};
auto dfs = [&](auto f,int x,int y) {
if(x==gi&&y==gj) {
ans++;
return;
}
vector<pair<int,int>> ns;
for(auto [dx,dy] : dir) {
int nx = x+dx;
int ny = y+dy;
if(!in(nx,ny)) continue;
if(ng.at(nx).at(ny)) continue;
ns.push_back(pair(nx,ny));
ng.at(nx).at(ny) = true;
}
for(auto [nx,ny] : ns) {
f(f,nx,ny);
}
for(auto [nx,ny] : ns) {
ng.at(nx).at(ny) = false;
}
};
dfs(dfs,si,sj);
cout << ans << endl;
return 0;
}