結果

問題 No.5015 Escape from Labyrinth
ユーザー 👑 platinumplatinum
提出日時 2023-03-07 19:27:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,631 bytes
コンパイル時間 2,284 ms
コンパイル使用メモリ 213,488 KB
実行使用メモリ 4,564 KB
スコア 0
最終ジャッジ日時 2023-04-15 11:30:38
合計ジャッジ時間 6,983 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
testcase_94 WA -
testcase_95 WA -
testcase_96 WA -
testcase_97 WA -
testcase_98 WA -
testcase_99 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:113:50: 警告: ‘gx’ may be used uninitialized [-Wmaybe-uninitialized]
  113 |         string goal = find_path(ky, kx, gy, gx, S);
      |                                                  ^
main.cpp:94:33: 備考: ‘gx’ はここで定義されています
   94 |         int sy, sx, ky, kx, gy, gx;
      |                                 ^~
main.cpp:113:50: 警告: ‘gy’ may be used uninitialized [-Wmaybe-uninitialized]
  113 |         string goal = find_path(ky, kx, gy, gx, S);
      |                                                  ^
main.cpp:94:29: 備考: ‘gy’ はここで定義されています
   94 |         int sy, sx, ky, kx, gy, gx;
      |                             ^~
main.cpp:113:50: 警告: ‘kx’ may be used uninitialized [-Wmaybe-uninitialized]
  113 |         string goal = find_path(ky, kx, gy, gx, S);
      |                                                  ^
main.cpp:94:25: 備考: ‘kx’ はここで定義されています
   94 |         int sy, sx, ky, kx, gy, gx;
      |                         ^~
main.cpp:113:50: 警告: ‘ky’ may be used uninitialized [-Wmaybe-uninitialized]
  113 |         string goal = find_path(ky, kx, gy, gx, S);
      |                                                  ^
main.cpp:94:21: 備考: ‘ky’ はここで定義されています
   94 |         int sy, sx, ky, kx, gy, gx;
      |                     ^~
main.cpp:110:54: 警告: ‘sx’ may be used uninitialized [-Wmaybe-uninitialized]
  110 |         string find_key = find_path(sy, sx, ky, kx, S);
      |                                                      ^
main.cpp:94:17: 備考: ‘sx’ はここで定義されています
   94 |         int sy, sx, ky, kx, gy, gx;
      |                 ^~
main.cpp:110:54: 警告: ‘sy’ may be used uninitialized [-Wmaybe-uninitialized]
  110 |         string find_key = find_path(sy, sx, ky, kx, S);
      |                                      

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int grid_size = 60;
int dy[4] = {-1, 1, 0, 0};
int dx[4] = {0, 0, -1, 1};
string dir = "UDLR";

void file_input(){
	FILE *in = freopen("sample_in/testcase_001.txt", "r", stdin);
}
void file_output(){
	FILE *out = freopen("sample_out/testcase_001.txt", "w", stdout);
}

// 探知機の情報
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(){
	//file_input();
	//file_output();

	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;
	int Q = ans.size();
	cout << Q << endl;
	for(int i = 0; i < Q; i++){
		cout << "M " << ans[i] << endl;
	}

	return 0;
}
0