Submission #661179

#TimeUsernameProblemLanguageResultExecution timeMemory
661179mychecksedadPrisoner Challenge (IOI22_prison)C++17
90 / 100
11 ms1024 KiB
#include <bits/stdc++.h>
using namespace std;



vector<vector<int>> devise_strategy(int n){
	int b = 0, cur = 2;
	while(cur < 5000){
		cur = cur * 3 + 2;
		b++;
	}

	vector<string> dp;
	function<void(int, string)> generate = [&](int depth, string str){
		dp.push_back(str + string(b - depth + 1, 'L'));
		if(depth != b){
			for(char i = '0'; i <= '2'; ++i){
				generate(depth + 1, str + i);
			}
		}
		dp.push_back(str + string(b - depth + 1, 'R'));
	};

	generate(0, "");
	vector<vector<int>> v(3*b + 1);

	for(int i = 0; i <= 3*b; ++i) v[i].resize(n + 1);
	for(int i = 0; i <= 3*b; ++i){
		int s = (i+2)/3, t = (i+2)%3;
		v[i][0] = (s % 2); // s is even: A, s is odd: B
		for(int j = 1; j <= n; ++j){
			if(s == 0){
				if(dp[j][s] == 'L'){
					v[i][j] = -1;
				}else if(dp[j][s] == 'R'){
					v[i][j] = -2;
				}else{
					v[i][j] = (s * 3) + 1 + (dp[j][s] - '0');
				}
			}else if(s % 2){
				int abit = t;
				int bbit = dp[j][s - 1] - '0';
				if(dp[j][s - 1] == 'R'){
					v[i][j] = -1;
				}else if(dp[j][s - 1] == 'L'){
					v[i][j] = -2;
				}else if(abit < bbit){
					v[i][j] = -1;
				}else if(bbit < abit){
					v[i][j] = -2;
				}else if(dp[j][s] == 'L'){
					v[i][j] = -2;
				}else if(dp[j][s] == 'R'){
					v[i][j] = -1;
				}else{
					v[i][j] = (s * 3) + 1 + (dp[j][s] - '0');
				}
			}else{
				int abit = dp[j][s - 1] - '0';
				int bbit = t;
				if(dp[j][s - 1] == 'L'){
					v[i][j] = -1;
				}else if(dp[j][s - 1] == 'R'){
					v[i][j] = -2;
				}else if(abit < bbit){
					v[i][j] = -1;
				}else if(bbit < abit){
					v[i][j] = -2;
				}else if(dp[j][s] == 'L'){
					v[i][j] = -1;
				}else if(dp[j][s] == 'R'){
					v[i][j] = -2;
				}else{
					v[i][j] = (s * 3) + 1 + (dp[j][s] - '0');
				}
			}
		}
	}

	return v;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...