結果

問題 No.2928 Gridpath
ユーザー 寝癖寝癖
提出日時 2024-10-12 16:45:02
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,495 ms / 2,000 ms
コード長 4,288 bytes
コンパイル時間 4,722 ms
コンパイル使用メモリ 319,392 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 16:45:22
合計ジャッジ時間 13,418 ms
ジャッジサーバーID
(参考情報)
judge / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#include <atcoder/all>
namespace neguse {}
using namespace std;
using namespace atcoder;
using namespace neguse;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, n - 1, -1)
#define rrepi(i, a, b) for (int i = int(a); i > int(b); --i)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep)(__VA_ARGS__)
#define _each1(i, v) for (auto &i : v)
#define _each2(i, j, v) for (auto &[i, j] : v)
#define each(...) _overload3(__VA_ARGS__, _each2, _each1, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define SUM(x) accumulate(all(x), 0LL)
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define ACC(x, acc) partial_sum(all(x), acc.begin()+1)
#define SORT(x) sort(all(x))
#define RSORT(x) sort(rall(x))
#define REVERSE(x) reverse(all(x))
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define print(x) cout << (x) << '\n'
#define yes(f) cout << ((f) ? "Yes" : "No") << '\n'
#define ge(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define gt(v, x) (int)(upper_bound(all(v), x) - v.begin())
#define le(v, x) (int)(upper_bound(all(v), x) - v.begin()) - 1
#define lt(v, x) (int)(lower_bound(all(v), x) - v.begin()) - 1
template <class T> bool chmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template <class T> bool chmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
ostream &operator<<(ostream &os, const modint998244353 &a) { return os << a.val(); }
ostream &operator<<(ostream &os, const modint1000000007 &a) { return os << a.val(); }
istream &operator>>(istream &is, modint998244353 &a) { int64_t t; is >> t; a = t; return is; }
istream &operator>>(istream &is, modint1000000007 &a) { int64_t t; is >> t; a = t; return is; }
template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) { return is >> p.first >> p.second; }
template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &x : v) os << x << ' '; return os; }
template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { for (const vector<T> &x : v) os << x << '\n'; return os; }
int main() {
int H, W, Si, Sj, Ti, Tj;
cin >> H >> W >> Si >> Sj >> Ti >> Tj;
Si--, Sj--, Ti--, Tj--;
vector<vector<bool>> used(H, vector<bool>(W));
used[Si][Sj] = true;
vpii path = {{Si, Sj}};
int ans = 0;
vpii dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
auto check = [&]() -> bool {
vvi dist = vvi(H, vi(W, -1));
dist[Si][Sj] = 0;
queue<pii> q;
q.emplace(Si, Sj);
while (!q.empty()) {
auto [i, j] = q.front(); q.pop();
for (auto [di, dj]: dir) {
int ni = i + di, nj = j + dj;
if (ni < 0 || nj < 0 || ni >= H || nj >= W || !used[ni][nj] || dist[ni][nj] != -1) continue;
dist[ni][nj] = dist[i][j] + 1;
q.emplace(ni, nj);
}
}
return path.size()-1 == dist[Ti][Tj];
};
auto dfs = [&](auto self, int i, int j) -> void {
if (i == Ti && j == Tj) {
if (check()) ans++;
return;
}
for (auto [di, dj]: dir) {
int ni = i + di, nj = j + dj;
if (ni < 0 || nj < 0 || ni >= H || nj >= W || used[ni][nj]) continue;
used[ni][nj] = true;
path.emplace_back(ni, nj);
self(self, ni, nj);
used[ni][nj] = false;
path.pop_back();
}
};
dfs(dfs, Si, Sj);
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0