結果
| 問題 |
No.5006 Hidden Maze
|
| コンテスト | |
| ユーザー |
kyo1
|
| 提出日時 | 2022-06-12 15:16:44 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 63 ms / 2,000 ms |
| コード長 | 2,595 bytes |
| コンパイル時間 | 2,383 ms |
| 実行使用メモリ | 22,624 KB |
| スコア | 34,829 |
| 平均クエリ数 | 652.32 |
| 最終ジャッジ日時 | 2022-06-12 15:16:59 |
| 合計ジャッジ時間 | 10,906 ms |
|
ジャッジサーバーID (参考情報) |
judge15 / 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'};
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, 3);
vector<vector<optional<char>>> P(H, vector<optional<char>>(W, nullopt));
for (int k = 0; k < K; k++) {
for (auto&& e : P) {
fill(e.begin(), e.end(), nullopt);
}
queue<pair<int, int>> que;
que.emplace(0, 0);
while (!que.empty()) {
const auto [y, x] = que.front();
que.pop();
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];
que.emplace(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;
}
kyo1