This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "paint.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 2e5 + 5;
const int MAXK = 1e2 + 5;
const double eps = 1e-9;
bool dp[2][MAXK][MAXN];
int sm[MAXN];
int force[MAXN][2];
string solve_puzzle(string s, vi c) {
int n, k;
s = "_" + s;
n = s.size(), k = c.size();
s.pb('_');
dp[0][0][0] = 1;
for (int i = 1; i <= n; i++) {
if (s[i] != 'X')
dp[0][0][i] = dp[0][0][i - 1];
else
dp[0][0][i] = 0;
sm[i] = sm[i - 1] + (int) (s[i] == '_');
}
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= n; j++) {
if (s[j] == 'X')
continue;
dp[0][i][j] = dp[0][i][j - 1];
if (j >= c[i - 1] + 1 && sm[j - 1] == sm[j - 1 - c[i - 1]])
dp[0][i][j] |= dp[0][i - 1][j - 1 - c[i - 1]];
}
}
dp[1][k][n + 1] = 1;
for (int i = n; i > 0; i--) {
if (s[i] != 'X')
dp[1][k][i] = dp[1][k][i + 1];
else
dp[1][k][i] = 0;
}
for (int i = k - 1; i >= 0; i--) {
for (int j = n; j > 0; j--) {
if (s[j] != 'X')
dp[1][i][j] = dp[1][i][j + 1];
if (j + c[i] <= n && s[j + c[i]] != 'X' && sm[j - 1] == sm[j + c[i] - 1])
dp[1][i][j] |= dp[1][i + 1][j + 1 + c[i]];
}
}
for (int i = 1; i < n; i++)
for (int j = 0; j <= k; j++)
if (dp[0][j][i] && dp[1][j][i + 1] && s[i] != 'X')
force[i][0] = 1;
for (int i = 1; i <= k; i++)
for (int j = 0; j < n - c[i - 1]; j++)
if (dp[0][i - 1][j] && dp[1][i][j + c[i - 1] + 2] && sm[j] == sm[j + c[i - 1]] && s[j] != 'X' && s[j + c[i - 1] + 1] != 'X') {
force[j + 1][1]++;
force[j + c[i - 1] + 1][1]--;
}
for (int i = 1; i <= n; i++)
force[i][1] += force[i - 1][1];
string ans;
for (int i = 1; i < n; i++) {
if (force[i][0] > 0 && force[i][1] > 0)
ans.pb('?');
else if (force[i][0] > 0)
ans.pb('_');
else if (force[i][1] > 0)
ans.pb('X');
}
return ans;
}
/*int main()
{
cerr << solve_puzzle("...........", {2,3,4}) << "\n";
return 0;
}*/
# | 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... |