This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// ~ Be Name Khoda ~ //
#include "paint.h"
#include <bits/stdc++.h>
#include <cstdlib>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int maxn = 1e6 + 10;
const int maxn5 = 2e5 + 5;
const int maxnk = 103;
const int maxn3 = 1e3 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e18;
bitset <maxn5> av[2][maxnk];
int ps[maxn5], cnt[maxn5];
bool w[maxn5];
int get_num(int l, int r){
return ps[r] - (l ? ps[l - 1] : 0);
}
std::string solve_puzzle(std::string s, std::vector<int> c) {
int k = c.size();
int n = s.size();
if(n == 1)
return "X";
bool ok = true;
for(int i = 0; i < n; i++)
ps[i] = (s[i] == '_') + (i ? ps[i - 1] : 0);
for(int i = 0; i < n; i++){
if(s[i] == 'X')
ok = false;
if(!ok)
break;
av[0][0][i] = true;
}
//cout << ps[5] << ' ' << ps[4] << endl;
ok = true;
for(int i = n - 1; i >= 0; i--){
if(s[i] == 'X')
ok = false;
if(!ok)
break;
av[1][0][i] = true;
}
for(int i = 1; i <= k; i++){
for(int j = 0; j < n; j++){
if(j && s[j] != 'X')
av[0][i][j] = av[0][i][j - 1];
if(j >= c[i - 1] - 1 && get_num(j - c[i - 1] + 1, j) == 0){
//if(i == 2 && j == 5)
// cout << "ha? " << get_num(j - c[i - 1] + 1, j) << ' ' << c[i - 1] << endl;
av[0][i][j] = (av[0][i][j] || (j - c[i - 1] >= 0 ? (s[j - c[i - 1]] != 'X' && (j - c[i - 1] - 1 >= 0 ? av[0][i - 1][j - c[i - 1] - 1] : (i <= 1))) : (i <= 1)));
}
}
for(int j = n - 1; j >= 0; j--){
if(j + 1 < n && s[j] != 'X')
av[1][i][j] = av[1][i][j + 1];
if(n - j >= c[k - (i)] && get_num(j, j + c[k - (i)] - 1) == 0){
av[1][i][j] = (av[1][i][j] || (j + c[k - (i)] < n ? (s[j + c[k - (i)]] != 'X' && (j + c[k - (i)] + 1 < n ? av[1][i - 1][j + c[k - (i)] + 1] : (i <= 1))) : (i <= 1)));
//if(i == 2 && j == 7)
// cout << (j + c[k - (i)] < n ? (s[j + c[k - (i)]] != 'X' && (j + c[k - (i)] + 1 < n ? av[1][i - 1][j + c[k - (i)] + 1] : true)) : true));
}
}
}
//for(int i = 0; i <= k; i++) for(int j = 0; j < n; j++)
// cout << i << ' ' << j << ' ' << av[0][i][j] << ' ' << av[1][i][j] << endl;
string ret = "";
for(int i = 0; i < n; i++){
if(i == 0)
w[i] = (s[i] != 'X' && av[1][k][i + 1]);
if(i == n - 1)
w[i] = (s[i] != 'X' && av[0][k][i - 1]);
for(int j = 0; j <= k; j++){
if(i > 0 && i + 1 < n)
w[i] |= (s[i] != 'X' && av[0][j][i - 1] && av[1][k - j][i + 1]);
//if(i ==2 && j == 1)
// cout << "OK " << (i >= c[j - 1] - 1) << ' ' << get_num(i - c[j - 1] + 1, i) << endl;
if(j && i >= c[j - 1] - 1 && get_num(i - c[j - 1] + 1, i) == 0){
//if(i == 2 && j == 1)
// cout << "here " << endl;
if(i - c[j - 1] >= 0 ? (s[i - c[j - 1]] != 'X' && (i - c[j - 1] - 1 >= 0 ? av[0][j - 1][i - c[j - 1] - 1] : (j <= 1))) : (j <= 1)){
//if(i == 2 && j == 1)
// cout << "then " << endl;
if(i == n - 1 ? (j == k) : (s[i + 1] != 'X' && (i + 1 == n - 1 ? (j == k) : av[1][k - j][i + 2]))){
cnt[i - c[j - 1] + 1]++;
cnt[i + 1]--;
// cout << "for " << i << ' ' << j << ' ' << i - c[j - 1] + 1 << ' ' << i << endl;
}
}
}
}
}
int cur = 0;
for(int i = 0; i < n; i++){
cur += cnt[i];
if(s[i] != '.')
ret.pb(s[i]);
else if(w[i] && cur)
ret.pb('?');
else if(w[i])
ret.pb('_');
else
ret.pb('X');
}
return ret;
}
# | 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... |