This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// ItnoE
#include<bits/stdc++.h>
using namespace std;
const int N = 200005, K = 109;
int X[N], U[N], W[N], B[N], M[K][N];
bool dp[K][N];
string solve_puzzle(string S, vector < int > C)
{
int n = (int)S.size();
int k = (int)C.size();
S = '.' + S;
C.insert(C.begin(), 0);
for (int i = 1; i <= n; i ++)
{
X[i] = X[i - 1] + (S[i] != '_');
U[i] = U[i - 1] + (S[i] != 'X');
}
dp[0][0] = 1;
for (int j = 0; j <= k; j ++)
for (int i = 1; i <= n; i ++)
{
if (S[i] != 'X' && dp[j][i - 1])
dp[j][i] = 1;
if (j == 1 && i == C[j] && X[i] - X[i - C[j]] == C[j])
dp[j][i] = 1;
if (j && i > C[j] && X[i] - X[i - C[j]] == C[j] && S[i - C[j]] != 'X' && dp[j - 1][i - C[j] - 1])
dp[j][i] = 1;
}
assert(dp[k][n]);
queue < pair < int , int > > qu;
qu.push({n, k});
while (qu.size())
{
int i = qu.front().first;
int j = qu.front().second;
qu.pop();
if (M[j][i]) continue;
M[j][i] = 1;
if (S[i] != 'X' && dp[j][i - 1])
qu.push({i - 1, j}), W[i] ++, W[i + 1] --;
if (j == 1 && i == C[j] && X[i] - X[i - C[j]] == C[j])
B[1] ++, B[i + 1] --;
if (j && i > C[j] && X[i] - X[i - C[j]] == C[j] && S[i - C[j]] != 'X' && dp[j - 1][i - C[j] - 1])
qu.push({i - C[j] - 1, j - 1}), B[i - C[j] + 1] ++, B[i + 1] --, W[i - C[j]] ++, W[i - C[j] + 1] --;
}
string R = "";
for (int i = 1; i <= n; i ++)
{
W[i] += W[i - 1];
B[i] += B[i - 1];
if (W[i] && !B[i])
R += '_';
else if (B[i] && !W[i])
R += 'X';
else
R += '?';
}
return (R);
}
# | 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... |