結果

問題 No.5006 Hidden Maze
ユーザー square1001square1001
提出日時 2022-06-12 17:28:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 4,017 bytes
コンパイル時間 1,716 ms
実行使用メモリ 22,856 KB
スコア 87,773
平均クエリ数 123.27
最終ジャッジ日時 2022-06-12 17:28:29
合計ジャッジ時間 9,416 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
21,940 KB
testcase_01 AC 29 ms
21,992 KB
testcase_02 AC 25 ms
22,624 KB
testcase_03 AC 22 ms
22,576 KB
testcase_04 AC 25 ms
22,704 KB
testcase_05 AC 29 ms
22,624 KB
testcase_06 AC 25 ms
22,016 KB
testcase_07 AC 34 ms
22,016 KB
testcase_08 AC 41 ms
22,612 KB
testcase_09 AC 30 ms
21,952 KB
testcase_10 AC 27 ms
21,952 KB
testcase_11 AC 24 ms
21,760 KB
testcase_12 AC 30 ms
21,940 KB
testcase_13 AC 28 ms
21,904 KB
testcase_14 AC 74 ms
21,928 KB
testcase_15 AC 31 ms
22,228 KB
testcase_16 AC 20 ms
21,904 KB
testcase_17 AC 22 ms
21,992 KB
testcase_18 AC 36 ms
22,444 KB
testcase_19 AC 26 ms
21,940 KB
testcase_20 AC 22 ms
21,780 KB
testcase_21 AC 23 ms
21,928 KB
testcase_22 AC 26 ms
22,444 KB
testcase_23 AC 25 ms
21,904 KB
testcase_24 AC 31 ms
21,760 KB
testcase_25 AC 27 ms
21,940 KB
testcase_26 AC 71 ms
22,228 KB
testcase_27 AC 29 ms
21,904 KB
testcase_28 AC 24 ms
22,228 KB
testcase_29 AC 56 ms
22,264 KB
testcase_30 AC 22 ms
22,576 KB
testcase_31 AC 23 ms
21,904 KB
testcase_32 AC 36 ms
22,588 KB
testcase_33 AC 28 ms
22,576 KB
testcase_34 AC 26 ms
21,928 KB
testcase_35 AC 25 ms
22,288 KB
testcase_36 AC 32 ms
21,768 KB
testcase_37 AC 76 ms
21,980 KB
testcase_38 AC 23 ms
21,940 KB
testcase_39 AC 24 ms
22,488 KB
testcase_40 AC 27 ms
21,952 KB
testcase_41 AC 22 ms
21,964 KB
testcase_42 AC 25 ms
22,240 KB
testcase_43 AC 32 ms
21,892 KB
testcase_44 AC 23 ms
22,624 KB
testcase_45 AC 54 ms
21,756 KB
testcase_46 AC 104 ms
21,904 KB
testcase_47 AC 32 ms
21,952 KB
testcase_48 AC 108 ms
22,228 KB
testcase_49 AC 103 ms
21,992 KB
testcase_50 AC 27 ms
21,952 KB
testcase_51 AC 37 ms
21,892 KB
testcase_52 AC 26 ms
22,288 KB
testcase_53 AC 53 ms
21,768 KB
testcase_54 AC 30 ms
21,904 KB
testcase_55 AC 32 ms
21,768 KB
testcase_56 AC 26 ms
21,780 KB
testcase_57 AC 27 ms
22,600 KB
testcase_58 AC 24 ms
21,892 KB
testcase_59 AC 25 ms
21,780 KB
testcase_60 AC 24 ms
21,916 KB
testcase_61 AC 23 ms
22,564 KB
testcase_62 AC 24 ms
21,892 KB
testcase_63 AC 25 ms
21,916 KB
testcase_64 AC 24 ms
21,856 KB
testcase_65 AC 40 ms
22,600 KB
testcase_66 AC 24 ms
21,904 KB
testcase_67 AC 26 ms
22,624 KB
testcase_68 AC 33 ms
22,704 KB
testcase_69 AC 25 ms
21,892 KB
testcase_70 AC 22 ms
21,780 KB
testcase_71 AC 29 ms
21,768 KB
testcase_72 AC 23 ms
21,952 KB
testcase_73 AC 28 ms
21,952 KB
testcase_74 AC 23 ms
22,288 KB
testcase_75 AC 28 ms
22,624 KB
testcase_76 AC 42 ms
21,760 KB
testcase_77 AC 45 ms
22,476 KB
testcase_78 AC 31 ms
22,608 KB
testcase_79 AC 126 ms
21,780 KB
testcase_80 AC 23 ms
22,444 KB
testcase_81 AC 25 ms
22,588 KB
testcase_82 AC 28 ms
22,004 KB
testcase_83 AC 29 ms
22,704 KB
testcase_84 AC 41 ms
21,940 KB
testcase_85 AC 26 ms
22,432 KB
testcase_86 AC 21 ms
22,004 KB
testcase_87 AC 30 ms
21,904 KB
testcase_88 AC 25 ms
22,588 KB
testcase_89 AC 89 ms
22,240 KB
testcase_90 AC 23 ms
21,916 KB
testcase_91 AC 23 ms
22,856 KB
testcase_92 AC 24 ms
21,756 KB
testcase_93 AC 23 ms
21,952 KB
testcase_94 AC 41 ms
22,228 KB
testcase_95 AC 23 ms
22,216 KB
testcase_96 AC 20 ms
21,780 KB
testcase_97 AC 24 ms
22,004 KB
testcase_98 AC 28 ms
22,444 KB
testcase_99 AC 31 ms
22,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
	yukicoder score contest (2022.6.12)
	author: square1001
	
	<< solution outline >>
	- repeat outputting the track with "the highest probability"
	  - probability estimation = bayesian
	  - assume that the probability to be walls are "independent"
	- highest probability track: search by dijkstra's algorithm
*/

#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

uint64_t seed = 123456789ULL;
uint64_t xorshift64() {
	seed ^= seed << 13;
	seed ^= seed >> 7;
	seed ^= seed << 17;
	return seed;
}
int rand_int(int l, int r) {
	return l + int(xorshift64() % (r - l));
}
double randouble() {
	return double(xorshift64()) / double(uint64_t(-1));
}

class state {
public:
	int x, y; double prob;
	state() : x(-1), y(-1), prob(0.0) {};
	state(int x_, int y_, double prob_) : x(x_), y(y_), prob(prob_) {};
	bool operator<(const state& s) const {
		return prob < s.prob;
	}
};

int solve(int H, int W, double p) {
	// ---------- INITIAL CONFIGURATION ---------- //
	const vector<int> dx = { 1, 0, -1, 0 };
	const vector<int> dy = { 0, 1, 0, -1 };
	const string ds = "DRUL";
	const int T = 1000;
	const double wallp = 150.0 / 760.0; // (= ~19.7%)
	vector<double> wallprob(T + 1);
	for (int i = 0; i <= T; i++) {
		wallprob[i] = wallp / (wallp + (1.0 - wallp) * pow(p, i));
	}
	vector<vector<int> > wallx(H - 1, vector<int>(W, 0)); // wall between (x, y) and (x+1, y)
	vector<vector<int> > wally(H, vector<int>(W - 1, 0)); // wall between (x, y) and (x, y+1)
	
	// ---------- GAME LOOP ---------- //
	int iteration = 1;
	while (true) {
		// step #1. pre-process
		vector<vector<double> > maxprob(H, vector<double>(W, 0.0));
		maxprob[0][0] = 1.0;
		priority_queue<state> que;
		que.push(state(0, 0, 1.0));
		vector<vector<bool> > vis(H, vector<bool>(W, false));
		vector<vector<pair<int, int> > > precoord(H, vector<pair<int, int> >(W, make_pair(-1, -1)));
		while (!que.empty()) {
			state u = que.top();
			que.pop();
			if (vis[u.x][u.y]) {
				continue;
			}
			vis[u.x][u.y] = true;
			for (int i = 0; i < 4; i++) {
				int nx = u.x + dx[i], wx = (dx[i] == -1 ? u.x - 1 : u.x);
				int ny = u.y + dy[i], wy = (dy[i] == -1 ? u.y - 1 : u.y);
				if (0 <= nx && nx < H && 0 <= ny && ny < W) {
					int wallstate = (dx[i] != 0 ? wallx[wx][wy] : wally[wx][wy]);
					double nprob = u.prob * (1.0 - (wallstate == -1 ? 0.0 : wallprob[wallstate])) * (1.0 - p * 2.7);
					nprob *= 1.0 - randouble() * 1.0e-7;
					if (maxprob[nx][ny] < nprob) {
						maxprob[nx][ny] = nprob;
						precoord[nx][ny] = make_pair(u.x, u.y);
						que.push(state(nx, ny, maxprob[nx][ny]));
					}
				}
			}
		}
		
		// step #2. calculate & output the track
		pair<int, int> cur = make_pair(H - 1, W - 1);
		string str;
		while (cur != make_pair(0, 0)) {
			pair<int, int> nxt = precoord[cur.first][cur.second];
			for (int i = 0; i < 4; i++) {
				if (nxt.first + dx[i] == cur.first && nxt.second + dy[i] == cur.second) {
					str += ds[i];
					break;
				}
			}
			cur = nxt;
		}
		reverse(str.begin(), str.end());
		cout << str << endl;
		cerr << "#" << iteration << ": prob = " << maxprob[H - 1][W - 1] << endl;
		
		// step #3. read input
		int res;
		cin >> res;
		if (res == -1) {
			return iteration;
		}
		
		// step #4. after-process
		int curx = 0, cury = 0;
		for (int i = 0; i <= res; i++) {
			int dir = ds.find(str[i]);
			int nx = curx + dx[dir], wx = (dx[dir] == -1 ? curx - 1 : curx);
			int ny = cury + dy[dir], wy = (dy[dir] == -1 ? cury - 1 : cury);
			if (dx[dir] != 0 && wallx[wx][wy] != -1) {
				wallx[wx][wy] = (i != res ? -1 : wallx[wx][wy] + 1);
			}
			if (dy[dir] != 0 && wally[wx][wy] != -1) {
				wally[wx][wy] = (i != res ? -1 : wally[wx][wy] + 1);
			}
			curx = nx;
			cury = ny;
		}
		iteration += 1;
	}
	return -1;
}

int main() {
	int H, W, PN;
	cin >> H >> W >> PN;
	int ops = solve(H, W, double(PN) / 100);
	cerr << "# of operations: " << ops << endl;
	cerr << "Score: " << (ops != -1 ? 1001 - ops : -1) << endl;
	return 0;
}
0