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>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#include "paint.h"
string solve_puzzle(string s, vector<int> c) {
int n = size(s), k = size(c);
vector<int> w(n);
REP(i, n)
w[i] = (s[i] == '_') + (i != 0 ? w[i - 1] : 0);
auto get = [&](int l, int r) {
return w[r] - (l != 0 ? w[l - 1] : 0);
};
vector<vector<bool>> suff(k + 1, vector<bool>(n + 1));
suff[k][n] = true;
for(int i = k; i >= 0; i--) {
for(int j = n - 1; j >= 0; j--) {
if(s[j] != 'X' && suff[i][j + 1])
suff[i][j] = true;
if(i < k) {
int r = j + c[i] - 1;
if(n <= r || get(j, r)) continue;
if(i < k - 1 && (n <= r + 1 || s[r + 1] == 'X')) continue;
if(suff[i + 1][(i < k - 1 ? r + 1 : r) + 1])
suff[i][j] = true;
}
}
}
vector<int> f(n + 1), e(n + 1);
vector<vector<bool>> pref(k + 1, vector<bool>(n + 1));
pref[0][0] = true;
REP(i, k + 1) REP(j, n) {
if(!pref[i][j]) continue;
if(s[j] != 'X') {
pref[i][j + 1] = true;
if(suff[i][j + 1]) e[j] = true;
}
if(i < k) {
int r = j + c[i] - 1;
if(n <= r || get(j, r)) continue;
if(i < k - 1 && (n <= r + 1 || s[r + 1] == 'X')) continue;
int p = (i < k - 1 ? r + 1 : r);
pref[i + 1][p + 1] = true;
if(suff[i + 1][p + 1]) {
f[j]++, f[r + 1]--;
if(i < k - 1) e[p] = true;
}
}
}
FOR(i, 1, n)
f[i] += f[i - 1];
string ans;
REP(i, n) {
if(e[i] && f[i]) ans += "?";
else if(e[i]) ans += "_";
else ans += "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... |