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>
namespace {
const int N = 2e5 + 5, K = 105;
int a[N], pf[N];
bool p[N][K], s[N][K], b[N];
std::string solve(const std::string &S, const std::vector<int> c) {
int n = S.size(), k = c.size();
for (int i = 0; i < n; ++i) {
pf[i + 1] = pf[i] + (S[i] == '_');
}
p[0][0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= k; ++j) {
if (!p[i][j]) {
continue;
}
if (S[i] != 'X') {
p[i + 1][j] = 1;
}
if (j < k) {
int l = c[j];
if (i + l < n && S[i + l] != 'X' && pf[i + l] - pf[i] == 0) {
p[i + l + 1][j + 1] = 1;
}
}
}
}
s[n + 1][k + 1] = 1;
for (int i = n + 1; i > 1; --i) {
for (int j = 1; j <= k + 1; ++j) {
if (!s[i][j]) {
continue;
}
if (S[i - 2] != 'X') {
s[i - 1][j] = 1;
}
if (j > 1) {
int l = c[j - 2];
if (i - l > 1 && S[i - l - 2] != 'X' && pf[i - 1] - pf[i - l - 1] == 0) {
s[i - l - 1][j - 1] = 1;
}
}
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= k; ++j) {
b[i] |= p[i][j] && s[i][j + 1];
if (j < k && i + c[j] - 1 <= n && p[i - 1][j] && s[i + c[j]][j + 2] && pf[i + c[j] - 1] - pf[i - 1] == 0) {
++a[i];
--a[i + c[j]];
}
}
}
std::string res(n, '?');
for (int i = 1; i <= n; ++i) {
a[i] += a[i - 1];
if (!b[i]) {
res[i - 1] = 'X';
}
if (!a[i]) {
res[i - 1] = '_';
}
}
return res;
}
}
std::string solve_puzzle(std::string s, std::vector<int> c) {
return solve(s, c);
}
# | 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... |