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 <bits/stdc++.h>
using namespace std;
#include "paint.h"
int n, k;
vector<bool> hi;
vector<int> cl;
vector<vector<bool>> dp;
vector<vector<bool>> seT;
vector<int> wh, bl;
vector<int> numWhite;
bool checkWhite(int l, int r)
{
int cnt = numWhite[r - 1];
if (l)
cnt -= numWhite[l - 1];
return cnt;
}
bool DP(int i, int j)
{
if (i <= 0)
return j == 0;
if (seT[i][j])
return dp[i][j];
bool b = false;
if (j > 0)
{
int size = cl[j - 1];
if (i >= size && (i == size || !hi[i - size - 1]) && !checkWhite(i - size, i))
{
if (DP(i - size - 1, j - 1))
{
b = true;
if (i != n)
bl[i]--;
bl[i - size]++;
if (i - size > 0)
wh[i - size - 1]++;
}
}
}
if (!hi[i - 1])
{
if (DP(i - 1, j))
{
b = true;
wh[i - 1]++;
}
}
seT[i][j] = true;
return dp[i][j] = b;
}
string solve_puzzle(string s, vector<int> c)
{
n = s.size();
k = c.size();
cl = c;
hi = vector<bool>(n);
numWhite = vector<int>(n);
seT = dp = vector<vector<bool>>(n, vector<bool>(k));
for (int i = 0; i < n; i++)
{
numWhite[i] += numWhite[max(i - 1, 0)];
if (s[i] == 'X')
hi[i] = true;
if (s[i] == '_')
numWhite[i]++;
}
wh = bl = vector<int>(n);
DP(n, k);
int black = 0;
string out;
for (int i = 0; i < n; i++)
{
black += bl[i];
if (black && wh[i])
out.push_back('?');
else if (black)
out.push_back('X');
else
out.push_back('_');
}
return out;
}
#ifdef _DEBUG
signed main()
{
cin.tie(0);
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
string s;
cin >> s;
vector<int> blub(k);
for (int &x : blub)
cin >> x;
cout << solve_puzzle(s, blub);
}
#endif
# | 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... |