結果
問題 | No.5015 Escape from Labyrinth |
ユーザー | trineutron |
提出日時 | 2023-04-05 22:23:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3 ms / 3,000 ms |
コード長 | 3,814 bytes |
コンパイル時間 | 2,650 ms |
コンパイル使用メモリ | 215,216 KB |
実行使用メモリ | 4,372 KB |
スコア | 23,890 |
最終ジャッジ日時 | 2023-04-15 11:34:04 |
合計ジャッジ時間 | 7,554 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
4,372 KB |
testcase_01 | AC | 3 ms
4,368 KB |
testcase_02 | AC | 3 ms
4,368 KB |
testcase_03 | AC | 2 ms
4,372 KB |
testcase_04 | AC | 3 ms
4,372 KB |
testcase_05 | AC | 3 ms
4,372 KB |
testcase_06 | AC | 3 ms
4,372 KB |
testcase_07 | AC | 3 ms
4,372 KB |
testcase_08 | AC | 2 ms
4,372 KB |
testcase_09 | AC | 3 ms
4,372 KB |
testcase_10 | AC | 3 ms
4,372 KB |
testcase_11 | AC | 2 ms
4,372 KB |
testcase_12 | AC | 3 ms
4,372 KB |
testcase_13 | AC | 2 ms
4,368 KB |
testcase_14 | AC | 2 ms
4,368 KB |
testcase_15 | AC | 2 ms
4,372 KB |
testcase_16 | AC | 2 ms
4,368 KB |
testcase_17 | AC | 3 ms
4,372 KB |
testcase_18 | AC | 2 ms
4,372 KB |
testcase_19 | AC | 2 ms
4,368 KB |
testcase_20 | AC | 2 ms
4,372 KB |
testcase_21 | AC | 2 ms
4,372 KB |
testcase_22 | AC | 2 ms
4,372 KB |
testcase_23 | AC | 2 ms
4,368 KB |
testcase_24 | AC | 2 ms
4,372 KB |
testcase_25 | AC | 3 ms
4,372 KB |
testcase_26 | AC | 3 ms
4,368 KB |
testcase_27 | AC | 3 ms
4,372 KB |
testcase_28 | AC | 3 ms
4,368 KB |
testcase_29 | AC | 3 ms
4,368 KB |
testcase_30 | AC | 2 ms
4,368 KB |
testcase_31 | AC | 3 ms
4,368 KB |
testcase_32 | AC | 3 ms
4,368 KB |
testcase_33 | AC | 3 ms
4,372 KB |
testcase_34 | AC | 2 ms
4,368 KB |
testcase_35 | AC | 3 ms
4,372 KB |
testcase_36 | AC | 2 ms
4,368 KB |
testcase_37 | AC | 3 ms
4,368 KB |
testcase_38 | AC | 2 ms
4,368 KB |
testcase_39 | AC | 3 ms
4,368 KB |
testcase_40 | AC | 3 ms
4,372 KB |
testcase_41 | AC | 2 ms
4,372 KB |
testcase_42 | AC | 2 ms
4,372 KB |
testcase_43 | AC | 3 ms
4,368 KB |
testcase_44 | AC | 3 ms
4,368 KB |
testcase_45 | AC | 3 ms
4,368 KB |
testcase_46 | AC | 3 ms
4,372 KB |
testcase_47 | AC | 2 ms
4,372 KB |
testcase_48 | AC | 2 ms
4,368 KB |
testcase_49 | AC | 2 ms
4,372 KB |
testcase_50 | AC | 2 ms
4,368 KB |
testcase_51 | AC | 3 ms
4,368 KB |
testcase_52 | AC | 2 ms
4,372 KB |
testcase_53 | AC | 3 ms
4,372 KB |
testcase_54 | AC | 2 ms
4,372 KB |
testcase_55 | AC | 3 ms
4,368 KB |
testcase_56 | AC | 2 ms
4,372 KB |
testcase_57 | AC | 2 ms
4,372 KB |
testcase_58 | AC | 3 ms
4,368 KB |
testcase_59 | AC | 3 ms
4,368 KB |
testcase_60 | AC | 3 ms
4,368 KB |
testcase_61 | AC | 3 ms
4,368 KB |
testcase_62 | AC | 3 ms
4,372 KB |
testcase_63 | AC | 2 ms
4,372 KB |
testcase_64 | AC | 3 ms
4,372 KB |
testcase_65 | AC | 2 ms
4,372 KB |
testcase_66 | AC | 2 ms
4,368 KB |
testcase_67 | AC | 2 ms
4,372 KB |
testcase_68 | AC | 3 ms
4,372 KB |
testcase_69 | AC | 3 ms
4,368 KB |
testcase_70 | AC | 3 ms
4,368 KB |
testcase_71 | AC | 3 ms
4,372 KB |
testcase_72 | AC | 2 ms
4,372 KB |
testcase_73 | AC | 2 ms
4,368 KB |
testcase_74 | AC | 2 ms
4,372 KB |
testcase_75 | AC | 2 ms
4,372 KB |
testcase_76 | AC | 3 ms
4,368 KB |
testcase_77 | AC | 2 ms
4,372 KB |
testcase_78 | AC | 2 ms
4,372 KB |
testcase_79 | AC | 2 ms
4,372 KB |
testcase_80 | AC | 3 ms
4,368 KB |
testcase_81 | AC | 3 ms
4,372 KB |
testcase_82 | AC | 3 ms
4,368 KB |
testcase_83 | AC | 2 ms
4,372 KB |
testcase_84 | AC | 3 ms
4,368 KB |
testcase_85 | AC | 2 ms
4,368 KB |
testcase_86 | AC | 3 ms
4,372 KB |
testcase_87 | AC | 2 ms
4,368 KB |
testcase_88 | AC | 2 ms
4,368 KB |
testcase_89 | AC | 2 ms
4,368 KB |
testcase_90 | AC | 3 ms
4,368 KB |
testcase_91 | AC | 3 ms
4,368 KB |
testcase_92 | AC | 3 ms
4,372 KB |
testcase_93 | AC | 2 ms
4,372 KB |
testcase_94 | AC | 2 ms
4,368 KB |
testcase_95 | AC | 2 ms
4,368 KB |
testcase_96 | AC | 2 ms
4,372 KB |
testcase_97 | AC | 2 ms
4,372 KB |
testcase_98 | AC | 3 ms
4,368 KB |
testcase_99 | AC | 2 ms
4,372 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; auto start = chrono::steady_clock::now(); auto elapsed() { return (chrono::steady_clock::now() - start).count(); } constexpr int grid_size = 60; // 迷宮の大きさ constexpr int max_hp = 1500; // 初期体力 constexpr int dy[4] = {-1, 1, 0, 0}; constexpr int dx[4] = {0, 0, -1, 1}; constexpr auto dir = "UDLR"; // 探知機の情報 struct enemy { int y, x, d, num; bool destroyed; enemy(int y, int x, int d, int num) { this->y = y, this->x = x, this->d = d; this->num = num; destroyed = false; } }; // 範囲外かどうか bool range_out(size_t y, size_t x) { return x >= grid_size or y >= grid_size; } // BFSによる経路探索 string find_path(int sy, int sx, int gy, int gx, const vector<string> &S) { int siz = S.size(); vector<vector<int>> dist(siz, vector<int>(siz, -1)); vector<vector<int>> seen(siz, vector<int>(siz)); dist[sy][sx] = 0; deque<pair<int, int>> q; q.emplace_back(sy, sx); while (!q.empty()) { pair<int, int> p = q.front(); q.pop_front(); int y = p.first, x = p.second; if (seen[y][x]) continue; seen[y][x] = true; for (int k = 0; k < 4; k++) { int ny = y + dy[k], nx = x + dx[k]; if (range_out(ny, nx)) continue; if (dist[ny][nx] != -1) continue; if (seen[ny][nx]) continue; char cell = S[ny][nx]; if (cell == '#' || cell == 'B' || cell == 'E') continue; if (cell == 'J') { dist[ny][nx] = dist[y][x] - 1000; q.emplace_front(ny, nx); } else { dist[ny][nx] = dist[y][x] + 1; q.emplace_back(ny, nx); } } } string res; if (dist[gy][gx] == -1) return res; int now_y = gy, now_x = gx, now_d = dist[gy][gx]; seen = vector<vector<int>>(siz, vector<int>(siz)); while (now_y != sy || now_x != sx) { bool moved = false; for (int k = 0; k < 4; k++) { int new_y = now_y + dy[k], new_x = now_x + dx[k]; if (range_out(new_y, new_x)) continue; bool good = false; if (dist[new_y][new_x] == now_d - 1 and S[now_y][now_x] != 'J') { good = true; } if (dist[new_y][new_x] == now_d + 1000 and S[now_y][now_x] == 'J') { good = true; } if (not good) continue; if (seen[new_y][new_x]) continue; seen[new_y][new_x] = true; now_y = new_y, now_x = new_x; now_d = dist[new_y][new_x]; res.push_back(dir[k ^ 1]); moved = true; break; } assert(moved); } reverse(res.begin(), res.end()); return res; } int main() { // 入力の受け取り int N, D, H; cin >> N >> D >> H; vector<string> S(N); for (int i = 0; i < N; i++) cin >> S[i]; int M; cin >> M; vector<enemy> E; for (int i = 0; i < M; i++) { int y, x, d; cin >> y >> x >> d; E.emplace_back(y, x, d, i); } string ans; int sy = -1, sx = -1, ky = -1, kx = -1, gy = -1, gx = -1; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (S[i][j] == 'S') { sy = i, sx = j; } else if (S[i][j] == 'K') { ky = i, kx = j; } else if (S[i][j] == 'G') { gy = i, gx = j; } } } // 鍵の取得 string find_key = find_path(sy, sx, ky, kx, S); ans += find_key; // 扉への移動 string goal = find_path(ky, kx, gy, gx, S); ans += goal; for (auto c : ans) { cout << "M " << c << endl; } return 0; }