結果
問題 | No.5015 Escape from Labyrinth |
ユーザー | platinum |
提出日時 | 2023-03-10 17:51:48 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3 ms / 3,000 ms |
コード長 | 2,456 bytes |
コンパイル時間 | 2,593 ms |
コンパイル使用メモリ | 213,540 KB |
実行使用メモリ | 4,376 KB |
スコア | 12,310 |
最終ジャッジ日時 | 2023-04-15 11:30:54 |
合計ジャッジ時間 | 7,759 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
4,368 KB |
testcase_01 | AC | 2 ms
4,368 KB |
testcase_02 | AC | 3 ms
4,368 KB |
testcase_03 | AC | 3 ms
4,372 KB |
testcase_04 | AC | 3 ms
4,368 KB |
testcase_05 | AC | 2 ms
4,368 KB |
testcase_06 | AC | 3 ms
4,368 KB |
testcase_07 | AC | 2 ms
4,368 KB |
testcase_08 | AC | 2 ms
4,368 KB |
testcase_09 | AC | 3 ms
4,368 KB |
testcase_10 | AC | 3 ms
4,368 KB |
testcase_11 | AC | 2 ms
4,368 KB |
testcase_12 | AC | 2 ms
4,368 KB |
testcase_13 | AC | 2 ms
4,372 KB |
testcase_14 | AC | 3 ms
4,368 KB |
testcase_15 | AC | 2 ms
4,368 KB |
testcase_16 | AC | 3 ms
4,368 KB |
testcase_17 | AC | 2 ms
4,368 KB |
testcase_18 | AC | 2 ms
4,368 KB |
testcase_19 | AC | 2 ms
4,372 KB |
testcase_20 | AC | 3 ms
4,372 KB |
testcase_21 | AC | 3 ms
4,372 KB |
testcase_22 | AC | 3 ms
4,368 KB |
testcase_23 | AC | 2 ms
4,368 KB |
testcase_24 | AC | 3 ms
4,368 KB |
testcase_25 | AC | 3 ms
4,372 KB |
testcase_26 | AC | 3 ms
4,372 KB |
testcase_27 | AC | 3 ms
4,368 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 | 2 ms
4,372 KB |
testcase_32 | AC | 2 ms
4,372 KB |
testcase_33 | AC | 2 ms
4,368 KB |
testcase_34 | AC | 2 ms
4,368 KB |
testcase_35 | AC | 2 ms
4,372 KB |
testcase_36 | AC | 3 ms
4,368 KB |
testcase_37 | AC | 2 ms
4,368 KB |
testcase_38 | AC | 2 ms
4,368 KB |
testcase_39 | AC | 3 ms
4,368 KB |
testcase_40 | AC | 2 ms
4,368 KB |
testcase_41 | AC | 2 ms
4,368 KB |
testcase_42 | AC | 3 ms
4,368 KB |
testcase_43 | AC | 3 ms
4,368 KB |
testcase_44 | AC | 3 ms
4,372 KB |
testcase_45 | AC | 2 ms
4,372 KB |
testcase_46 | AC | 2 ms
4,372 KB |
testcase_47 | AC | 2 ms
4,368 KB |
testcase_48 | AC | 3 ms
4,368 KB |
testcase_49 | AC | 2 ms
4,372 KB |
testcase_50 | AC | 3 ms
4,368 KB |
testcase_51 | AC | 2 ms
4,372 KB |
testcase_52 | AC | 2 ms
4,368 KB |
testcase_53 | AC | 3 ms
4,368 KB |
testcase_54 | AC | 3 ms
4,372 KB |
testcase_55 | AC | 3 ms
4,376 KB |
testcase_56 | AC | 2 ms
4,368 KB |
testcase_57 | AC | 2 ms
4,368 KB |
testcase_58 | AC | 3 ms
4,368 KB |
testcase_59 | AC | 3 ms
4,368 KB |
testcase_60 | AC | 2 ms
4,368 KB |
testcase_61 | AC | 3 ms
4,368 KB |
testcase_62 | AC | 2 ms
4,372 KB |
testcase_63 | AC | 3 ms
4,372 KB |
testcase_64 | AC | 2 ms
4,372 KB |
testcase_65 | AC | 3 ms
4,372 KB |
testcase_66 | AC | 3 ms
4,368 KB |
testcase_67 | AC | 3 ms
4,368 KB |
testcase_68 | AC | 3 ms
4,368 KB |
testcase_69 | AC | 2 ms
4,372 KB |
testcase_70 | AC | 3 ms
4,372 KB |
testcase_71 | AC | 3 ms
4,372 KB |
testcase_72 | AC | 3 ms
4,368 KB |
testcase_73 | AC | 2 ms
4,368 KB |
testcase_74 | AC | 3 ms
4,368 KB |
testcase_75 | AC | 2 ms
4,368 KB |
testcase_76 | AC | 3 ms
4,372 KB |
testcase_77 | AC | 2 ms
4,368 KB |
testcase_78 | AC | 3 ms
4,372 KB |
testcase_79 | AC | 3 ms
4,372 KB |
testcase_80 | AC | 2 ms
4,372 KB |
testcase_81 | AC | 3 ms
4,368 KB |
testcase_82 | AC | 2 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 | 2 ms
4,372 KB |
testcase_87 | AC | 3 ms
4,372 KB |
testcase_88 | AC | 3 ms
4,372 KB |
testcase_89 | AC | 3 ms
4,372 KB |
testcase_90 | AC | 2 ms
4,368 KB |
testcase_91 | AC | 2 ms
4,368 KB |
testcase_92 | AC | 3 ms
4,368 KB |
testcase_93 | AC | 3 ms
4,368 KB |
testcase_94 | AC | 2 ms
4,368 KB |
testcase_95 | AC | 3 ms
4,368 KB |
testcase_96 | AC | 2 ms
4,372 KB |
testcase_97 | AC | 3 ms
4,372 KB |
testcase_98 | AC | 2 ms
4,376 KB |
testcase_99 | AC | 3 ms
4,368 KB |
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内: main.cpp:105:50: 警告: ‘gx’ may be used uninitialized [-Wmaybe-uninitialized] 105 | string goal = find_path(ky, kx, gy, gx, S); | ^ main.cpp:86:33: 備考: ‘gx’ はここで定義されています 86 | int sy, sx, ky, kx, gy, gx; | ^~ main.cpp:105:50: 警告: ‘gy’ may be used uninitialized [-Wmaybe-uninitialized] 105 | string goal = find_path(ky, kx, gy, gx, S); | ^ main.cpp:86:29: 備考: ‘gy’ はここで定義されています 86 | int sy, sx, ky, kx, gy, gx; | ^~ main.cpp:105:50: 警告: ‘kx’ may be used uninitialized [-Wmaybe-uninitialized] 105 | string goal = find_path(ky, kx, gy, gx, S); | ^ main.cpp:86:25: 備考: ‘kx’ はここで定義されています 86 | int sy, sx, ky, kx, gy, gx; | ^~ main.cpp:105:50: 警告: ‘ky’ may be used uninitialized [-Wmaybe-uninitialized] 105 | string goal = find_path(ky, kx, gy, gx, S); | ^ main.cpp:86:21: 備考: ‘ky’ はここで定義されています 86 | int sy, sx, ky, kx, gy, gx; | ^~ main.cpp:102:54: 警告: ‘sx’ may be used uninitialized [-Wmaybe-uninitialized] 102 | string find_key = find_path(sy, sx, ky, kx, S); | ^ main.cpp:86:17: 備考: ‘sx’ はここで定義されています 86 | int sy, sx, ky, kx, gy, gx; | ^~ main.cpp:102:54: 警告: ‘sy’ may be used uninitialized [-Wmaybe-uninitialized] 102 | string find_key = find_path(sy, sx, ky, kx, S); |
ソースコード
#include <bits/stdc++.h> using namespace std; const int grid_size = 60; // 迷宮の大きさ const int max_hp = 1500; // 初期体力 int dy[4] = {-1, 1, 0, 0}; int dx[4] = {0, 0, -1, 1}; string 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(int y, int x){ if(y < 0 || y >= grid_size) return true; if(x < 0 || x >= grid_size) return true; return false; } // BFSによる経路探索 string find_path(int sy, int sx, int gy, int gx, vector<string> &S){ int siz = S.size(); vector<vector<int>> dist(siz, vector<int>(siz, -1)); dist[sy][sx] = 0; queue<pair<int,int>> q; q.emplace(sy, sx); while(!q.empty()){ pair<int,int> p = q.front(); q.pop(); int y = p.first, x = p.second; 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; char cell = S[ny][nx]; if(cell == '#' || cell == 'B' || cell == 'E') continue; dist[ny][nx] = dist[y][x] + 1; q.emplace(ny, nx); } } string res; if(dist[gy][gx] == -1) return res; int now_y = gy, now_x = gx, now_d = dist[gy][gx]; 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; if(dist[new_y][new_x] != now_d - 1) continue; now_y = new_y, now_x = new_x; now_d--; 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, sx, ky, kx, gy, gx; 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 s : ans){ cout << "M " << s << endl; } return 0; }