This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef LOCAL
#include "paint.h"
#endif // LOCAL
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define forinc(a,b,c) for(int a=b, _c=c; a<=_c; ++a)
#define fordec(a,b,c) for(int a=b, _c=c; a>=_c; --a)
#define forv(a,b) for(auto &a:b)
#define fasty ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ii pair<int,int>
#define fi first
#define se second
#define ar array
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) (x>>(i-1)&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))
const int N=2e5+5;
int n,k;
bool pf[N][105],sf[N][105];
int bl[N],wh[N];
int sum[N];
string solve_puzzle(string s,vector<int> a){
n=s.size();
k=a.size();
forinc(i,1,n) sum[i]=sum[i-1]+(s[i-1]=='_');
pf[0][0]=sf[n][k]=true;
forinc(i,0,n-1){
forinc(j,0,k){
if(s[i]=='X') pf[i+1][j]|=pf[i][j];
if(j<k){
if(i+a[j]<n && s[i+a[j]]!='X'&&sum[i+a[j]]==sum[i]){
pf[i+a[j]+1][j+1]|=pf[i][j];
}
}
}
}
fordec(i,n,1){
forinc(j,0,k){
if(s[i-1]=='X') sf[i-1][j]|=sf[i][j];
if(j>=1){
if(i-a[j-1]>0&&s[i-a[j-1]-1]!='X'&&sum[i-a[j-1]-1]==sum[i]){
sf[i-a[j-1]-1][j-1]|=sf[i][j];
}
}
}
}
string res;
forinc(i,0,n-1){
forinc(j,0,k){
wh[i]=max(wh[i],(int)min(pf[i+1][j],sf[i][j]));
}
forinc(j,0,k-1){
if(i+a[j]<=n && pf[i][j] && sf[i+a[j]][j+1] && sum[i+a[j]]==sum[i]){
++bl[i];
--bl[i+a[j]];
}
}
if(i>=1) bl[i]+=bl[i-1];
if(bl[i]&&wh[i]){
res+=('?');
} else if(bl[i]){
res+=('X');
} else res+=('_');
}
return res;
}
/*
int32_t main(){
fasty;
if(fopen("in.txt","r")) freopen("in.txt","r",stdin);
string s; cin>>s;
int n_; cin>>n_;
vector<int> a(n_);
forv(v,a) cin>>v;
cout<<solve_puzzle(s,a);
}
*/
# | 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... |