結果

問題 No.5006 Hidden Maze
ユーザー kyo1kyo1
提出日時 2022-06-12 15:35:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 3,334 bytes
コンパイル時間 2,446 ms
実行使用メモリ 22,864 KB
スコア 41,866
平均クエリ数 581.98
最終ジャッジ日時 2022-06-12 15:35:53
合計ジャッジ時間 12,505 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
純コード判定しない問題か言語
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
21,940 KB
testcase_01 AC 43 ms
21,928 KB
testcase_02 AC 30 ms
21,904 KB
testcase_03 AC 29 ms
22,540 KB
testcase_04 AC 79 ms
21,892 KB
testcase_05 AC 53 ms
22,588 KB
testcase_06 AC 39 ms
21,756 KB
testcase_07 AC 73 ms
21,952 KB
testcase_08 AC 74 ms
22,420 KB
testcase_09 AC 75 ms
22,704 KB
testcase_10 AC 27 ms
22,204 KB
testcase_11 AC 34 ms
21,916 KB
testcase_12 AC 43 ms
22,576 KB
testcase_13 AC 25 ms
21,892 KB
testcase_14 AC 71 ms
21,892 KB
testcase_15 AC 23 ms
21,868 KB
testcase_16 AC 25 ms
22,540 KB
testcase_17 AC 34 ms
21,892 KB
testcase_18 AC 77 ms
22,252 KB
testcase_19 AC 68 ms
22,204 KB
testcase_20 AC 27 ms
21,756 KB
testcase_21 AC 26 ms
21,928 KB
testcase_22 AC 28 ms
21,928 KB
testcase_23 AC 45 ms
21,916 KB
testcase_24 AC 80 ms
21,880 KB
testcase_25 AC 34 ms
21,768 KB
testcase_26 AC 78 ms
21,768 KB
testcase_27 AC 70 ms
22,004 KB
testcase_28 AC 74 ms
22,600 KB
testcase_29 AC 74 ms
21,928 KB
testcase_30 AC 48 ms
22,480 KB
testcase_31 AC 28 ms
22,552 KB
testcase_32 AC 45 ms
21,780 KB
testcase_33 AC 50 ms
22,600 KB
testcase_34 AC 24 ms
21,892 KB
testcase_35 AC 73 ms
22,600 KB
testcase_36 AC 71 ms
21,940 KB
testcase_37 AC 69 ms
21,892 KB
testcase_38 AC 78 ms
22,192 KB
testcase_39 AC 19 ms
22,864 KB
testcase_40 AC 26 ms
22,864 KB
testcase_41 AC 54 ms
22,204 KB
testcase_42 AC 55 ms
22,004 KB
testcase_43 AC 65 ms
21,780 KB
testcase_44 AC 26 ms
21,892 KB
testcase_45 AC 74 ms
21,992 KB
testcase_46 AC 76 ms
21,756 KB
testcase_47 AC 48 ms
22,264 KB
testcase_48 AC 67 ms
21,928 KB
testcase_49 AC 70 ms
21,980 KB
testcase_50 AC 30 ms
22,264 KB
testcase_51 AC 67 ms
22,444 KB
testcase_52 AC 38 ms
21,968 KB
testcase_53 AC 74 ms
21,880 KB
testcase_54 AC 22 ms
22,600 KB
testcase_55 AC 73 ms
21,756 KB
testcase_56 AC 49 ms
21,576 KB
testcase_57 AC 81 ms
22,444 KB
testcase_58 AC 76 ms
22,252 KB
testcase_59 AC 39 ms
21,808 KB
testcase_60 AC 27 ms
21,980 KB
testcase_61 AC 23 ms
21,940 KB
testcase_62 AC 34 ms
22,576 KB
testcase_63 AC 36 ms
21,928 KB
testcase_64 AC 57 ms
21,892 KB
testcase_65 AC 72 ms
22,004 KB
testcase_66 AC 72 ms
22,264 KB
testcase_67 AC 69 ms
21,880 KB
testcase_68 AC 70 ms
21,980 KB
testcase_69 AC 67 ms
22,276 KB
testcase_70 AC 19 ms
21,928 KB
testcase_71 AC 22 ms
22,432 KB
testcase_72 AC 42 ms
22,264 KB
testcase_73 AC 37 ms
21,928 KB
testcase_74 AC 53 ms
21,952 KB
testcase_75 AC 73 ms
21,928 KB
testcase_76 AC 68 ms
21,600 KB
testcase_77 AC 58 ms
22,204 KB
testcase_78 AC 81 ms
21,992 KB
testcase_79 AC 79 ms
21,928 KB
testcase_80 AC 36 ms
22,204 KB
testcase_81 AC 30 ms
21,868 KB
testcase_82 AC 29 ms
21,904 KB
testcase_83 AC 20 ms
21,880 KB
testcase_84 AC 74 ms
21,940 KB
testcase_85 AC 32 ms
22,552 KB
testcase_86 AC 68 ms
21,756 KB
testcase_87 AC 74 ms
21,904 KB
testcase_88 AC 73 ms
22,856 KB
testcase_89 AC 74 ms
22,228 KB
testcase_90 AC 30 ms
21,796 KB
testcase_91 AC 32 ms
22,252 KB
testcase_92 AC 35 ms
22,552 KB
testcase_93 AC 26 ms
22,216 KB
testcase_94 AC 44 ms
22,276 KB
testcase_95 AC 69 ms
21,892 KB
testcase_96 AC 28 ms
21,768 KB
testcase_97 AC 68 ms
21,820 KB
testcase_98 AC 72 ms
21,892 KB
testcase_99 AC 26 ms
21,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

constexpr int K = 1000;
constexpr std::array<std::int32_t, 4> DX = {1, -1, 0, 0};
constexpr std::array<std::int32_t, 4> DY = {0, 0, 1, -1};
constexpr std::array<char, 4> DC = {'R', 'L', 'D', 'U'};

template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int H, W, p;
  cin >> H >> W >> p;

  vector<vector<double>> B(H, vector<double>(W - 1, 1));
  vector<vector<double>> C(H - 1, vector<double>(W, 1));
  double T = pow(static_cast<double>(p) / 100, 2);

  vector<vector<optional<char>>> P(H, vector<optional<char>>(W, nullopt));
  vector<vector<double>> Q(H, vector<double>(W, 1 << 30));

  for (int k = 0; k < K; k++) {
    for (auto&& e : P) {
      fill(e.begin(), e.end(), nullopt);
    }
    for (auto&& e : Q) {
      fill(e.begin(), e.end(), 1 << 30);
    }
    Q[0][0] = 0;

    priority_queue<pair<double, pair<int, int>>, vector<pair<double, pair<int, int>>>,
                   greater<pair<double, pair<int, int>>>>
        que;
    que.emplace(0, make_pair(0, 0));
    while (!que.empty()) {
      const auto [d, pxy] = que.top();
      que.pop();
      const int y = pxy.first;
      const int x = pxy.second;
      if (Q[y][x] < d) continue;
      for (int i = 0; i < 4; i++) {
        const int ny = y + DY[i];
        const int nx = x + DX[i];
        if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
        if (i <= 1 && B[ny][min(x, nx)] <= T) continue;
        if (2 <= i && C[min(y, ny)][nx] <= T) continue;
        if (P[ny][nx]) continue;
        P[ny][nx] = DC[i];
        double w = i <= 1 ? B[ny][min(x, nx)] : C[min(y, ny)][nx];
        if (w == 100) {
          w = 0;
        } else {
          w = 1 - w;
        }
        if (chmin(Q[ny][nx], Q[y][x] + w)) {
          que.emplace(Q[ny][nx], make_pair(ny, nx));
        }
      }
    }

    bool is_ok = true;
    string res = "";
    int y = H - 1, x = W - 1;
    while (y != 0 || x != 0) {
      if (!P[y][x].has_value()) {
        is_ok = false;
        break;
      }
      res += P[y][x].value();
      for (int i = 0; i < 4; i++) {
        if (DC[i] == P[y][x].value()) {
          y -= DY[i];
          x -= DX[i];
          break;
        }
      }
    }
    if (is_ok) reverse(res.begin(), res.end());
    if (!is_ok) {
      for (auto&& e : B) {
        fill(e.begin(), e.end(), 0);
      }
      for (auto&& e : C) {
        fill(e.begin(), e.end(), 0);
      }
      k--;
      continue;
    }

    cout << res << endl;

    int r;
    cin >> r;
    if (r == -1) break;

    y = 0, x = 0;
    for (int i = 0; i <= r; i++) {
      int py = y, px = x, d = 0;
      for (int j = 0; j < 4; j++) {
        if (DC[j] == res[i]) {
          d = j;
          y += DY[j];
          x += DX[j];
          if (i < r && j < 2) {
            B[y][min(x, px)] = 100;
          } else if (i < r && j >= 2) {
            C[min(y, py)][x] = 100;
          }
          break;
        }
      }
      if (i == r) {
        if (d < 2) {
          if (B[y][min(x, px)] <= 1.0) B[y][min(x, px)] *= static_cast<double>(p) / 100;
        } else {
          if (C[min(y, py)][x] <= 1.0) C[min(y, py)][x] *= static_cast<double>(p) / 100;
        }
      }
    }
  }

  return 0;
}
0