#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define arr array
#define vec vector
#define str string
const int N = 2e5 + 5, K = 1e2 + 5;
int n, k;
arr<int, N> rq;
arr<int, K> sz;
arr<arr<int, N>, 3> sm;
int qry(int x, int l, int r) {
if (l > r) return 0;
return sm[x][r] - sm[x][l - 1];
}
void sm_cmp() {
for (int i = 1; i <= 2; i++)
for (int j = 1; j <= n; j++)
sm[i][j] = sm[i][j - 1] + (rq[j] == i);
}
arr<arr<bool, K>, N> lf;
void lf_cmp() {
for (int i = 1; i <= n; i++) {
int j = i - sz[1] + 1;
lf[i][1] = (j >= 1 && !qry(1, j, i) && !qry(2, 1, j - 1));
}
for (int c = 2; c <= k; c++) {
for (int i = 1; i <= n; i++) {
int j = i - sz[c] + 1;
if (j < 1) continue;
if (qry(1, j, i)) continue;
for (int x = j - 2; x >= 1; x--) {
if (qry(2, x + 1, j - 1)) continue;
lf[i][c] |= lf[x][c - 1];
}
}
}
// for (int i = 1; i <= n; i++)
// for (int c = 1; c <= k; c++)
// cout << i << " " << c << " : " << lf[i][c] << endl;
}
arr<arr<bool, K>, N> rg;
void rg_cmp() {
for (int i = 1; i <= n; i++) {
int j = i + sz[k] - 1;
rg[i][k] = (j <= n && !qry(1, i, j) && !qry(2, j + 1, n));
}
for (int c = k - 1; c >= 1; c--) {
for (int i = 1; i <= n; i++) {
int j = i + sz[c] - 1;
if (j > n) continue;
if (qry(1, i, j)) continue;
for (int x = j + 2; x <= n; x++) {
if (qry(2, j + 1, x - 1)) continue;
rg[i][c] |= rg[x][c + 1];
}
}
}
// for (int i = 1; i <= n; i++)
// for (int c = 1; c <= k; c++)
// cout << i << " " << c << " : " << rg[i][c] << endl;
}
bool ps1(int id) {
bool ans = false;
for (int i = 1; i < id; i++)
if (lf[i][k] && !qry(2, i + 1, n)) ans = true;
for (int i = id + 1; i <= n; i++)
if (rg[i][1] && !qry(2, 1, i - 1)) ans = true;
for (int c = 1; c < k; c++)
for (int i = 1; i < id; i++)
for (int j = id + 1; j <= n; j++)
if (lf[i][c] && rg[j][c + 1] && !qry(2, i + 1, j - 1)) ans = true;
return ans;
}
bool ps2(int id) {
bool ans = false;
for (int c = 1; c <= k; c++) {
for (int i = 1; i <= n; i++) {
int j = i + sz[c] - 1;
if (id < i || j < id) continue;
if (lf[j][c] && rg[i][c]) ans = true;
}
}
return ans;
}
str solve_puzzle(str _rq, vec<signed> _sz) {
n = _rq.size(), k = _sz.size();
for (int i = 1; i <= n; i++) {
if (_rq[i - 1] == '.') rq[i] = 0;
if (_rq[i - 1] == '_') rq[i] = 1;
if (_rq[i - 1] == 'X') rq[i] = 2;
}
for (int i = 1; i <= k; i++) sz[i] = _sz[i - 1];
sm_cmp();
lf_cmp();
rg_cmp();
str ans = "";
for (int i = 1; i <= n; i++) {
if (!ps1(i)) ans += 'X';
else if (!ps2(i)) ans += '_';
else ans += '?';
}
return ans;
}
Compilation message (stderr)
paint.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
paint_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |