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 <bits/stdc++.h>
#define pb push_back
using namespace std;
const int MAXN = 200055;
const int MAXK = 105;
bitset<MAXK> DA[2][MAXN], DB[2][MAXN];
int S[MAXN];
char A[MAXN];
int B[MAXK];
int N, K;
void reverse() {
reverse(A+1, A+N+1);
reverse(B+1, B+K+1);
}
void run(bitset<MAXK> DA[], bitset<MAXK> DB[]) {
DA[0][0] = true;
for(int i = 1; i <= N; i++) {
S[i] = S[i-1] + ('_' == A[i]);
for(int j = 0; j <= K; j++)
DA[i][j] = 'X' != A[i] && (DA[i-1][j] || DB[i-1][j]);
for(int j = 1; j <= K; j++)
DB[i][j] = B[j] <= i && DA[i-B[j]][j-1] && S[i] == S[i-B[j]];
}
}
string getAns() {
run(DA[0], DB[0]); reverse();
run(DA[1], DB[1]); reverse();
memset(S, 0, (N+1)<<2);
for(int j = 1; j <= K; j++) {
for(int s = 1, e = B[j]; e <= N; s++, e++) {
if(!DB[0][e][j] || !DB[1][N-s+1][K-j+1]) continue;
S[s]++; S[e+1]--;
}
}
string ret;
for(int i = 1; i <= N; i++) {
S[i] += S[i-1];
if(!S[i]) {
ret.pb('_');
continue;
}
bool t = false;
for(int j = 0; j <= K; j++) {
if(!DA[0][i][j] || !DA[1][N-i+1][K-j]) continue;
t = true;
break;
}
ret.pb(t ? '?' : 'X');
}
return ret;
}
std::string solve_puzzle(std::string s, std::vector<int> c) {
::N = s.length(); ::K = c.size();
for(int i = 0; i < ::N; i++) ::A[i+1] = s[i];
for(int i = 0; i < ::K; i++) ::B[i+1] = c[i];
return getAns();
}
# | 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... |