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 "grader.cpp"
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int pf[3][N], n, m;
int dp[202][N], pref[N], f[202][N];
int get(int l, int r, int tp){
if(l > r) return 0;
return pf[tp][r] - pf[tp][l - 1];
}
int Get(int l, int r, int tp){
if(l > r) return 0;
return f[tp][r] - f[tp][l - 1];
}
string solve_puzzle(string s, vector<int> c) {
n = (int)s.size();
m = (int)c.size();
s = ' ' + s;
for(int i = 1; i <= n; i ++){
if(s[i] == 'X')
pf[0][i] ++;
if(s[i] == '_')
pf[1][i] ++;
if(s[i] == '.')
pf[2][i] ++;
pf[0][i] += pf[0][i - 1];
pf[1][i] += pf[1][i - 1];
pf[2][i] += pf[2][i - 1];
}
for(int i = c[0]; i <= n; i ++){
if(get(i - c[0] + 1, i, 1) == 0 && get(1, i - c[0], 0) == 0 && (m != 1 || get(i + 1, n, 0) == 0))
dp[0][i] = 1;
}
for(int i = 1; i < m; i ++){
vector <int> pf(n + 1, 0), lastX(n + 1, 0);
for(int j = 1; j <= n; j ++){
pf[j] = pf[j - 1] + dp[i - 1][j];
}
for(int j = c[i] + 1; j <= n; j ++){
if(get(j - c[i] + 1, j, 1) == 0 && get(j - c[i], j - c[i], 0) == 0){
int sum = pf[j - c[i] - 1] - pf[lastX[j - c[i] - 1] + 1];
if(sum && (i != m - 1 || get(j + 1, n, 0) == 0)) dp[i][j] = 1;
}
if(s[j] == 'X')
lastX[j] = j;
lastX[j] = max(lastX[j], lastX[j - 1]);
}
}
for(int i = m - 2; i >= 0; i --){
vector <int> pf(n + 2, 0);
for(int j = n; j >= 1; j --){
pf[j] = pf[j + 1] + dp[i + 1][j];
}
for(int j = 1; j <= n; j ++){
if(dp[i][j] && (j + c[i + 1] + 1 > n || !pf[j + c[i + 1] + 1]))
dp[i][j] = 0;
}
}
for(int i = 0; i < m; i ++)
for(int j = 1; j <= n; j ++)
f[i][j] += f[i][j - 1] + dp[i][j];
string ans;
for(int i = 1; i <= n; i ++){
if(s[i] == '.'){
int canX = 0, can_ = 0;
for(int j = 0; j < m; j ++){
if(j == 0){
if(Get(i + c[j], n, 0))
can_ = 1;
} else {
if(Get(1, i - 1, j - 1) && Get(i + c[j], n, j))
can_ = 1;
}
if(Get(i, min(i + c[j] - 1, n), j))
canX = 1;
}
if(Get(1, i - 1, m - 1))
can_ = 1;
if(canX && can_)
ans += '?';
else if(canX)
ans += 'X';
else
ans += '_';
} else
ans += s[i];
}
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... |