結果
問題 | No.5006 Hidden Maze |
ユーザー |
![]() |
提出日時 | 2022-06-12 15:35:32 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.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 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 100 |
ソースコード
#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;}