#include "paint.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC target("popcnt")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using lld = long double;
using ii = pair<int,int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
using vpll = vector<pll>;
using vlld = vector<lld>;
#define all(x) x.begin(),x.end()
#define lsb(x) x&(-x)
#define gcd(a,b) __gcd(a,b)
#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fls cout.flush()
#define fore(i, l, r) for (auto i = l; i < r; i++)
#define fo(i, n) fore (i, 0, n)
#define forex(i, r, l) for (auto i = r-1; i >= l; i--)
#define ffo(i, n) forex (i, n, 0)
bool cmin(ll &a, ll b) { if (b < a) { a=b; return 1; } return 0; }
bool cmax(ll &a, ll b) { if (b > a) { a=b; return 1; } return 0; }
const int INF = 1e9 + 7;
const int mod = 1e9 + 7, LOG = 20;
void prec (ll n, ll k, string s, vector<int> &c, vector<vector<vector<bool>>> &dppref, vector<vector<vector<bool>>> &dpsuf, vector<int> &pf) {
s = 'w' + s + 'w';
{auto d = c;
c = vector<int>(1, 0);
fo (i, k) c.pb(d[i]);}
fore (i, 1, n+1) pf[i] = pf[i-1] + (s[i] == '_');
dppref[0][0][0] = 1;
dppref[0][0][1] = 1;
fore (i, 1, n+1) {
fo (j, k+1) {
// elegir nada
dppref[i][j][0] = ((dppref[i-1][j][0] || dppref[i-1][j][1]) && (s[i] != 'X' ? 1 : 0));
// elegir substring
if (c[j] <= i && j > 0) {
bool ok = (pf[i] - pf[i-c[j]] == 0 ? 1 : 0);
ok &= (s[i-c[j]] != 'X');
if (c[j] == i) dppref[i][j][1] = ((j == 1) && ok);
else dppref[i][j][1] = (dppref[i-c[j]][j-1][0] && ok);
}
}
}
dpsuf[n+1][0][0] = 1;
dpsuf[n+1][0][1] = 1;
forex (i, n+1, 1) {
fo (j, k+1) {
// elegir nada
dpsuf[i][j][0] = ((dpsuf[i+1][j][0] || dpsuf[i+1][j][1]) && (s[i] != 'X' ? 1 : 0));
// elegir substring
if (c[k-j+1] <= n - i + 1 && j > 0) {
bool ok = (pf[i+c[k-j+1]-1] - pf[i-1] == 0 ? 1 : 0);
ok &= (s[i+c[k-j+1]] != 'X');
if (c[k-j+1] == n - i + 1) dpsuf[i][j][1] = ((j == 1) && ok);
else dpsuf[i][j][1] = (dpsuf[i+c[k-j+1]][j-1][0] && ok);
}
}
}
}
string solve_puzzle(string s, vector<int> c) {
ll n = s.size(), k = c.size();
string ans = s;
vector<vector<vector<bool>>> dppref(n+3, vector<vector<bool>>(k+3, vector<bool>(2, 0ll))), dpsuf(n+3, vector<vector<bool>>(k+3, vector<bool>(2, 0ll)));
vector<vector<int>> func(k+3, vector<int>(n+3, 0ll));
vector<int> pf(n+3, 0ll);
prec(n, k, s, c, dppref, dpsuf, pf);
fore (j, 1, k+1) {
fore (i, 1, n+1) {
func[j][i] = (dppref[i][j][1] && dpsuf[i+1][k-j][0]);
func[j][i] += func[j][i-1];
}
}
fo (i, n) {
if (s[i] != '.') continue;
// cout << "Indice " << i << '\n';
s[i] = 'X';
// cout << "checar con X\n";
bool ok = 0;
// j = el indice del substring que uso que contenga a i
fore (j, 1, k+1) {
ok |= (func[j][min(ll(i+c[j]), n)] > func[j][i] ? 1 : 0);
}
// cout << ok << '\n';
if (ok) ans[i] = 'X';
// cout << "checar con Y\n";
ok = 0;
s[i] = '_';
fo (j, k+1) {
ok |= (dppref[i+1][j][0] && (dpsuf[i+2][k-j][0] || dpsuf[i+2][k-j][1]));
}
if (ok) ans[i] = (ans[i] == 'X' ? '?' : '_');
s[i] = '.';
}
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... |