結果
問題 | No.2695 Warp Zone |
ユーザー |
|
提出日時 | 2024-03-30 18:47:56 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,091 bytes |
コンパイル時間 | 2,374 ms |
コンパイル使用メモリ | 164,988 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-09-30 17:41:32 |
合計ジャッジ時間 | 3,682 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 4 WA * 20 |
ソースコード
#include <bits/stdc++.h>using namespace std;using i64 = long long;using P = pair<int, int>;#define yn(pope) (pope ? "Yes" : "No")#define rep(i, n, m) for (int i = (n); i < (m); i++)#define rrep(i, n, m) for (int i = (n); i > m; i--)#define IINF (1 << 30)#define INF (1ll << 60)#define all(v) v.begin(), v.end()int main() {int H, W, N;cin >> H >> W >> N;vector<P> from(N), to(N);rep(i, 0, N) {int a, b, c, d;cin >> a >> b >> c >> d;from[i] = {a, b};to[i] = {c, d};}map<P, int> memo;auto dfs = [&](auto self, int x, int y) -> int {if (memo.count({x, y}) == 1) {return memo[{x, y}];}if (x == H && y == W) {return memo[{x, y}] = 0;}int ans = (H - x) + (W - y);rep(i, 0, N) {auto [a, b] = from[i];auto [c, d] = to[i];if ((P){a, b} >= (P){c, d}) { continue; }if ((P){x, y} >= (P){a, b}) { continue; }ans = min(ans, (a - x) + (b - y) + 1 + self(self, c, d));}return memo[{x, y}] = ans;};cout << dfs(dfs, 1, 1) << endl;return 0;}