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 ll long long
#define F first
#define S second
#define pii pair<ll, ll>
const ll mod = 1e9 + 7;
const ll mxN = 3e5 + 2;
using namespace std;
bool dpP[200010][110][2], dpS[200010][110][2];
int prfx[200010], suff[200010];
int a[200010], b[200010];
string solve_puzzle(string s, vector<int> c)
{
int n = s.size(), k = c.size();
string s1 = "#";
s1 += s;
s = s1;
vector<int> c1;
c1.push_back(-1);
for (auto x : c)
c1.push_back(x);
c = c1;
for (int i = 1; i <= n; i++)
{
prfx[i] = prfx[i - 1] + (s[i] == '_');
}
dpP[0][0][0] = 1;
dpS[n + 1][k + 1][0] = 1;
dpS[n + 2][k + 1][0] = 1;
for (int j = 0; j <= k; j++)
{
for (int i = 1; i <= n; i++)
{
if (s[i] != 'X')
{
dpP[i][j][0] = dpP[i - 1][j][0];
}
if (s[i] != '_' && j)
{
if (i >= c[j])
{
if (prfx[i] == prfx[i - c[j]])
{
if (j == 1)
dpP[i][j][1] = dpP[i - c[j]][j - 1][0];
else if (i > c[j] && s[i - c[j]] != 'X')
dpP[i][j][1] = dpP[i - c[j] - 1][j - 1][0];
}
}
}
dpP[i][j][0] = max(dpP[i][j][0], dpP[i][j][1]);
// cout << dpP[i][j][0] << ' ';
}
// cout << '\n';
}
// cout<<'\n';
for (int i = n; i; i--)
{
suff[i] = suff[i + 1] + (s[i] == '_');
}
for (int j = k + 1; j; j--)
{
for (int i = n; i; i--)
{
if (s[i] != 'X')
{
dpS[i][j][0] = dpS[i + 1][j][0];
}
if (s[i] != '_' && j != k + 1)
{
if (n - i + 1 >= c[j])
{
if (suff[i] == suff[i + c[j]])
{
if (j == k)
dpS[i][j][1] = dpS[i + c[j]][j + 1][0];
else if (s[i + c[j]] != 'X')
dpS[i][j][1] = dpS[i + c[j] + 1][j + 1][0];
// cout<<i<<' '<<j<<' '<<dpS[i][j][1]<<'\n';
}
}
}
dpS[i][j][0] = max(dpS[i][j][0], dpS[i][j][1]);
// cout << dpS[i][j][1] << ' ';
}
// cout<<'\n';
}
// cout<<'\n';
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= k + 1; j++)
{
if (j != k + 1 && ((dpP[i][j][1] && dpS[i + 2][j + 1][0]) && (i == n || s[i + 1] != 'X')))
{
a[i - c[j] + 1] += 1;
a[i + 1] += -1;
}
if (i == 1 && (j != k + 1 && ((dpP[i - 1][j - 1][0] && dpS[i][j][1]) && (i == 1 || s[i - 1] != 'X'))))
{
a[i] += 1;
a[i + c[j]] += -1;
}
else if (j != k + 1 && ((dpP[i - 2][j - 1][0] && dpS[i][j][1]) && (i == 1 || s[i - 1] != 'X')))
{
// cout<<i<<' '<<j<<' '<<dpS[i][j][1]<<'\n';
a[i] += 1;
a[i + c[j]] += -1;
}
if (dpP[i - 1][j - 1][0] && dpS[i + 1][j][0])
b[i] = 1;
}
}
// cout<<a[4]<<'\n';
for (int i = 1; i <= n; i++)
{
a[i] += a[i - 1];
// cout<<a[i]<<' ';
}
// cout<<'\n';
string ans;
for (int i = 1; i <= n; i++)
{
char ch;
if (s[i] != '.')
{
ans += s[i];
continue;
}
if (a[i] && b[i])
ch = '?';
else if (a[i])
ch = 'X';
else if (b[i])
ch = '_';
ans += ch;
}
// cout<<ans<<' '<<"TEST";
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... |