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>
#include "paint.h"
using namespace std;
int canb[250002], cnt[250002], canw[250002], dpb[250002][102], dpa[250002][102];
string solve_puzzle(string s, vector<int> c) {
string ans;
int n = s.length(), k = c.size();
s = '$' + s;
for (int i = 1; i <= n + 1; ++i)
cnt[i] = cnt[i - 1] + (s[i] == '_');
dpb[0][0] = dpa[n + 1][k] = 1;
for (int i = 0; i < n; ++i)
for (int j = 0; j <= k; ++j) {
if (s[i + 1] != 'X')
dpb[i + 1][j] |= dpb[i][j];
if (j < k&& i + c[j] + 1 <= n && s[i + c[j] + 1] != 'X' && cnt[i] == cnt[i + c[j]])
dpb[i + c[j] + 1][j + 1] |= dpb[i][j];
}
for (int i = n + 1; i > 1; --i)
for (int j = 0; j <= k; ++j) {
if (s[i - 1] != 'X')
dpa[i - 1][j] |= dpa[i][j];
if (j && i - c[j - 1] - 1 >= 1 && s[i - c[j - 1] - 1] != 'X' && cnt[i - 1] == cnt[i - c[j - 1] - 1])
dpa[i - c[j - 1] - 1][j - 1] |= dpa[i][j];
}
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= k; ++j) {
if (s[i] != 'X' && dpb[i][j] && dpa[i][j])
canw[i] = 1;
if (j < k && i + c[j] <= n && dpb[i][j] && dpa[i + c[j] + 1][j + 1] && cnt[i] == cnt[i + c[j]])
++canb[i + 1], --canb[i + c[j] + 1];
}
for (int i = 1; i <= n; ++i)
canb[i] += canb[i - 1];
for (int i = 1; i <= n; ++i)
ans += ((canw[i] && canb[i]) ? '?' : canw[i] ? '_' : 'X');
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... |