結果

問題 No.2695 Warp Zone
ユーザー soldraysoldray
提出日時 2024-03-30 18:47:56
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,091 bytes
コンパイル時間 3,048 ms
コンパイル使用メモリ 162,500 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-30 18:48:00
合計ジャッジ時間 3,631 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 WA -
testcase_02 AC 1 ms
6,548 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
6,548 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
6,548 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
6,548 KB
testcase_25 AC 1 ms
6,548 KB
testcase_26 AC 1 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0