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 "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 10;
const int maxK = 110;
bool dp[maxN][maxK][2], dp2[maxN][maxK][2];
int cntBlack[maxN], cntWhite[maxN];
int canBlack[maxN], canWhite[maxN];
string solve_puzzle(string s, vector<int> c) {
int N = s.size(), K = c.size();
for (int i = 1; i <= N; ++i) {
cntBlack[i] = cntBlack[i-1] + (s[i-1] == 'X');
cntWhite[i] = cntWhite[i-1] + (s[i-1] == '_');
}
dp[0][0][0] = 1;
for (int i = 1; i <= N; ++i) dp[i][0][0] = (cntBlack[i] == 0);
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= K; ++j) {
if (s[i-1] != 'X') dp[i][j][0] = dp[i-1][j][0] || dp[i-1][j][1];
if (s[i-1] != '_') dp[i][j][1] = (i >= c[j-1]) && (cntWhite[i] - cntWhite[i-c[j-1]] == 0) && dp[i-c[j-1]][j-1][0];
}
}
dp2[N+1][K+1][0] = 1;
for (int i = N; i >= 1; --i) dp2[i][K+1][0] = (cntBlack[N] - cntBlack[i-1]) == 0;
for (int i = N; i >= 1; --i) {
for (int j = K; j >= 1; --j) {
if (s[i-1] != 'X') dp2[i][j][0] = dp2[i+1][j][0] || dp2[i+1][j][1];
if (s[i-1] != '_') dp2[i][j][1] = (N-i+1 >= c[j-1]) && (cntWhite[i+c[j-1]-1] - cntWhite[i-1]) == 0 && dp2[i+c[j-1]][j+1][0];
}
}
for (int i = 1; i <= N; ++i) {
for (int j = 0; j <= K; ++j) {
if (dp[i][j][0] && (dp2[i+1][j+1][0] || dp2[i+1][j+1][1])) canWhite[i]++, canWhite[i+1]--;
if (dp[i][j][1] && dp2[i+1][j+1][0]) canBlack[i-c[j-1]+1]++, canBlack[i+1]--;
}
}
for (int i = 1; i <= N; ++i) canBlack[i] += canBlack[i-1], canWhite[i] += canWhite[i-1];
string ans = "";
for (int i = 1; i <= N; ++i) {
if (canBlack[i] > 0 && canWhite[i] > 0) ans += "?";
if (canBlack[i] > 0 && canWhite[i] == 0) ans += "X";
if (canBlack[i] == 0 && canWhite[i] > 0) ans += "_";
}
return ans;
}
# | 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... |