#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], dpS[200010][110];
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] = 1;
dpS[n + 1][k + 1] = 1;
for (int j = 0; j <= k; j++)
{
for (int i = 1; i <= n; i++)
{
dpP[i][j] = dpP[i - 1][j];
if (j == 0)
{
dpP[i][j] = 1;
}
else
{
if (i >= c[j])
{
if (prfx[i] == prfx[i - c[j]])
{
if (j == 1)
dpP[i][j] = max(dpP[i][j], dpP[i - c[j]][j - 1]);
else
dpP[i][j] = max(dpP[i][j], dpP[i - c[j] - 1][j - 1]);
}
}
}
// cout << dpP[i][j] << ' ';
}
// 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--)
{
dpS[i][j] = dpS[i + 1][j];
if (j == k + 1)
{
dpS[i][j] = 1;
}
else
{
if (suff[i] == suff[i + c[j]])
{
if (j == k)
dpS[i][j] = max(dpS[i][j], dpS[i + c[j]][j + 1]);
else
dpS[i][j] = max(dpS[i][j], dpS[i + c[j] + 1][j + 1]);
}
}
// cout << dpS[i][j] << ' ';
}
// 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] && dpS[i + 1][j + 1]))
{
a[i - c[j] + 1] += 1;
a[i + 1] += -1;
}
if (j != k + 1 && (dpP[i - 1][j - 1] && dpS[i][j]))
{
a[i] += 1;
a[i + c[j] + 1] += -1;
}
if (dpP[i - 1][j - 1] && dpS[i + 1][j])
b[i] = 1;
}
}
for (int i = 1; i <= n; i++)
{
a[i] += a[i - 1];
}
string ans;
for (int i = 1; i <= n; i++)
{
char ch;
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 |
1 |
Correct |
1 ms |
2396 KB |
n = 13, m = 1 |
2 |
Correct |
1 ms |
2492 KB |
n = 18, m = 1 |
3 |
Correct |
1 ms |
2488 KB |
n = 17, m = 1 |
4 |
Correct |
1 ms |
2396 KB |
n = 1, m = 1 |
5 |
Correct |
1 ms |
2488 KB |
n = 20, m = 1 |
6 |
Correct |
1 ms |
2396 KB |
n = 20, m = 1 |
7 |
Correct |
1 ms |
2396 KB |
n = 20, m = 1 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
n = 13, m = 1 |
2 |
Correct |
1 ms |
2492 KB |
n = 18, m = 1 |
3 |
Correct |
1 ms |
2488 KB |
n = 17, m = 1 |
4 |
Correct |
1 ms |
2396 KB |
n = 1, m = 1 |
5 |
Correct |
1 ms |
2488 KB |
n = 20, m = 1 |
6 |
Correct |
1 ms |
2396 KB |
n = 20, m = 1 |
7 |
Correct |
1 ms |
2396 KB |
n = 20, m = 1 |
8 |
Correct |
1 ms |
2396 KB |
n = 20, m = 5 |
9 |
Incorrect |
1 ms |
2396 KB |
char #5 differ - expected: '_', found: '?' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
n = 13, m = 1 |
2 |
Correct |
1 ms |
2492 KB |
n = 18, m = 1 |
3 |
Correct |
1 ms |
2488 KB |
n = 17, m = 1 |
4 |
Correct |
1 ms |
2396 KB |
n = 1, m = 1 |
5 |
Correct |
1 ms |
2488 KB |
n = 20, m = 1 |
6 |
Correct |
1 ms |
2396 KB |
n = 20, m = 1 |
7 |
Correct |
1 ms |
2396 KB |
n = 20, m = 1 |
8 |
Correct |
1 ms |
2396 KB |
n = 20, m = 5 |
9 |
Incorrect |
1 ms |
2396 KB |
char #5 differ - expected: '_', found: '?' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
n = 13, m = 1 |
2 |
Correct |
1 ms |
2492 KB |
n = 18, m = 1 |
3 |
Correct |
1 ms |
2488 KB |
n = 17, m = 1 |
4 |
Correct |
1 ms |
2396 KB |
n = 1, m = 1 |
5 |
Correct |
1 ms |
2488 KB |
n = 20, m = 1 |
6 |
Correct |
1 ms |
2396 KB |
n = 20, m = 1 |
7 |
Correct |
1 ms |
2396 KB |
n = 20, m = 1 |
8 |
Correct |
1 ms |
2396 KB |
n = 20, m = 5 |
9 |
Incorrect |
1 ms |
2396 KB |
char #5 differ - expected: '_', found: '?' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
n = 13, m = 1 |
2 |
Correct |
1 ms |
2492 KB |
n = 18, m = 1 |
3 |
Correct |
1 ms |
2488 KB |
n = 17, m = 1 |
4 |
Correct |
1 ms |
2396 KB |
n = 1, m = 1 |
5 |
Correct |
1 ms |
2488 KB |
n = 20, m = 1 |
6 |
Correct |
1 ms |
2396 KB |
n = 20, m = 1 |
7 |
Correct |
1 ms |
2396 KB |
n = 20, m = 1 |
8 |
Correct |
1 ms |
2396 KB |
n = 20, m = 5 |
9 |
Incorrect |
1 ms |
2396 KB |
char #5 differ - expected: '_', found: '?' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
n = 13, m = 1 |
2 |
Correct |
1 ms |
2492 KB |
n = 18, m = 1 |
3 |
Correct |
1 ms |
2488 KB |
n = 17, m = 1 |
4 |
Correct |
1 ms |
2396 KB |
n = 1, m = 1 |
5 |
Correct |
1 ms |
2488 KB |
n = 20, m = 1 |
6 |
Correct |
1 ms |
2396 KB |
n = 20, m = 1 |
7 |
Correct |
1 ms |
2396 KB |
n = 20, m = 1 |
8 |
Correct |
1 ms |
2396 KB |
n = 20, m = 5 |
9 |
Incorrect |
1 ms |
2396 KB |
char #5 differ - expected: '_', found: '?' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
n = 13, m = 1 |
2 |
Correct |
1 ms |
2492 KB |
n = 18, m = 1 |
3 |
Correct |
1 ms |
2488 KB |
n = 17, m = 1 |
4 |
Correct |
1 ms |
2396 KB |
n = 1, m = 1 |
5 |
Correct |
1 ms |
2488 KB |
n = 20, m = 1 |
6 |
Correct |
1 ms |
2396 KB |
n = 20, m = 1 |
7 |
Correct |
1 ms |
2396 KB |
n = 20, m = 1 |
8 |
Correct |
1 ms |
2396 KB |
n = 20, m = 5 |
9 |
Incorrect |
1 ms |
2396 KB |
char #5 differ - expected: '_', found: '?' |
10 |
Halted |
0 ms |
0 KB |
- |