This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Black lives matter
#include <bits/stdc++.h>
#include "paint.h"
/// 500 485 462 A4
using namespace std;
typedef long long int ll;
typedef complex<double> point;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
//#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
const int N=2e5+100,K=110;
ll can[N],can1[N];
bool dp[N][K],pd[N][K];
ll par[N];
ll pr[N];
ll get(ll l,ll r){
return pr[r]-pr[l-1];
}
std::string solve_puzzle(std::string s, std::vector<int32_t> c) {
ll n=s.size();
ll k=c.size();
s='A'+s;
for (int i=1;i<=n;i++){
pr[i]=pr[i-1]+(s[i]=='_');
}
dp[0][0]=1;
pd[n+1][k+1]=1;
pd[n+2][k+1]=1;
for (int i=1;i<=n;i++){
for (int j=0;j<=k;j++){
if (s[i]!='X') dp[i][j]=dp[i-1][j];
if (j && i-c[j-1]>=0 && (get(i-c[j-1]+1,i)==0) && s[i-c[j-1]]!='X'){
dp[i][j]=max(dp[i][j],dp[max((ll)0,i-c[j-1]-1)][j-1]);
}
}
}
for (int i=n;i;i--){
for (int j=k+1;j;j--){
if (s[i]!='X') pd[i][j]=pd[i+1][j];
if (j!=k+1 && i+c[j-1]<=n+1 && get(i,i+c[j-1]-1)==0){
if (i+c[j-1]<=n && s[i+c[j-1]]=='X') continue;
pd[i][j]=max(pd[i][j],pd[i+c[j-1]+1][j+1]);
}
}
}
/*
for (int i=1;i<=n;i++){
for (int j=0;j<=k;j++){
cout << i << " " << j << " " << dp[i][j] << endl;
}
}
*/
for (int i=1;i<=n;i++){
if (s[i]=='.'){
for (int j=0;j<=k;j++){
if (dp[i-1][j] && pd[i+1][j+1]) can[i]=1;
if (j && i-c[j-1]>=0 && (get(i-c[j-1]+1,i)==0) && s[i-c[j-1]]!='X' && dp[max((ll)0,i-c[j-1]-1)][j-1] && pd[i+2][j+1]){
// cout << i << " " << j << endl;
par[i-c[j-1]+1]++;
par[i+1]--;
}
}
}
}
for (int i=1;i<=n;i++){
par[i]+=par[i-1];
}
string ans="";
for (int i=1;i<=n;i++){
if (s[i]!='.') ans+=s[i];
else{
if (can[i] && par[i]) ans+='?';
else if (can[i] && !par[i]) ans+='_';
else ans+='X';
}
}
return ans;
}
/*
const int S_MAX_LEN = 200 * 1000;
char buf[S_MAX_LEN + 1];
int32_t main() {
assert(1 == scanf("%s", buf));
std::string s = buf;
int c_len;
assert(1 == scanf("%d", &c_len));
std::vector<int> c(c_len);
for (int i = 0; i < c_len; i++) {
assert(1 == scanf("%d", &c[i]));
}
std::string ans = solve_puzzle(s, c);
printf("%s\n", ans.data());
return 0;
}
*/
# | 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... |