This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "paint.h"
#include <iostream>
#include<string>
#include<vector>
#define MAXN 100005
#define MAXK 105
using namespace std;
int N, K;
bool dp[MAXN][MAXK], done[MAXN][MAXK], canwhite[MAXN], canblack[MAXN];
string s;
vector <int> c;
bool gen(int i, int j) {
if (i >= N && j == K) {return(1);}
if (i >= N && j < K) {return(0);}
if (done[i][j]) {return(dp[i][j]);}
done[i][j]=true;
if (s[i] != 'X' && gen(i+1,j)) {
dp[i][j]=true;
canwhite[i]=true;
}
if (j < K && i + c[j] <= N) {
bool can = true;
for (int k=i; k<i+c[j]; k++) {
if (s[k] == '_') {
can=false;
break;
}
}
if (i+c[j] != N && s[i+c[j]] == 'X') {
can=false;
}
if (can && gen(i+c[j]+1, j+1)) {
dp[i][j]=true;
for (int k=i; k<i+c[j]; k++) {
canblack[k]=true;
}
canwhite[i+c[j]]=true;
}
}
return(dp[i][j]);
}
string solve_puzzle(string S, vector<int> C) {
N=S.size(), K=C.size();
s = S, c = C;
gen(0,0);
string Sol;
for (int i=0; i<N; i++) {
if (canblack[i] && canwhite[i]) {
Sol.push_back('?');
} else if (canblack[i]) {
Sol.push_back('X');
} else {
Sol.push_back('_');
}
}
return(Sol);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |