Submission #1021798

#TimeUsernameProblemLanguageResultExecution timeMemory
1021798vjudge1Paint By Numbers (IOI16_paint)C++17
80 / 100
3 ms860 KiB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e2 + 100;

int n, k;
bool dp[maxn][maxn];
int a[maxn];
int b[maxn];
int c[maxn];
string s;

bool ok(int l, int r, int c){
	if(c){
		if(b[r] > b[l-1]) return 0;
		return 1;
	} else{
		if(a[r] > a[l-1]) return 0;
		return 1;
	}
}

bool ok(){
	for(int i = 1; i <= n; i++){
		a[i] = a[i-1]; b[i] = b[i-1];
		if(s[i] == 'X') a[i]++;
		if(s[i] == '_') b[i]++;
		fill(dp[i], dp[i] + k + 1, 0);
	}
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= k; j++){
			if(ok(i, i, 0) && dp[i-1][j]){
				dp[i][j] = 1;
			}
			if(j){
				int l = i - c[j] - 1;
				if(j == 1) l++;
				if(l >= 0 && dp[l][j-1] && ok(i - c[j] + 1, i, 1) && (j == 1 || ok(l+1, l+1, 0))){
					dp[i][j] = 1;
				}
			}
		}
	}
	return dp[n][k];
}

string solve_puzzle(std::string S, std::vector<int> C){
	s = S;
	n = s.size();
	s = "#" + s; k = C.size();
	for(int i = 1; i <= k; i++){
		c[i] = C[i-1];
	}
	string res;
	vector<int> ans = {'.', '_', 'X', '?'};
	for(int i = 1; i <= n; i++){
		int x = 0;
		if(s[i] == '.'){
			s[i] = 'X';
			if(ok()) x |= 2;
			s[i] = '_';
			if(ok()) x |= 1;
			s[i] = '.';
		} else if(s[i] == 'X') x = 2;
		else x = 1;
		res.push_back(ans[x]);
	}
	return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...