This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<int> b , w ;
vector<int> c;
string a ;
vector<int> p ;
int n , k ;
bool theresno(int i , int j){
int minus = 0;
if(i) minus=p[i-1 ] ;
return (p[j]-minus)==0 ;
}
bool dp(int i , int j , int color){
if(i==n) return 1 ;
if(i>n) return 0 ;
if(color&&a[i]=='X') return 0 ;
if(color==0&&a[i]=='_') return 0 ;
//if(i==3&&color) cout << 1 << " " ;
bool ok = 0;//dp(i+1,j) ;
if(j==k){
ok=dp(i+1,j,1) ;
if(ok)w[i] =1 ;
}
else{
if(color){
ok = dp(i+1,j,0)|dp(i+1,j,1) ;
if(ok) w[i]=1 ;
}
else{
ok = dp(i+c[j],j+1,1)&theresno(i,i+c[j]-1) ;
if(ok) b[i]=1,b[i+c[j]]=-1 ;
}
}
//mem[i][j][color]
return ok ;
}
string solve_puzzle(string b , vector<int> cc){
//int n , k ;
a = b ;
c = cc ;
n = a.size() ;
k = c.size() ;
cin>>a ;
c.resize(k) ;
for(int& x : c) cin>>x ;
b.resize(n);
w.resize(n) ;
p.resize(n) ;
for(int i=0;i<n;i++){
if(i) p[i]+=p[i-1] ;
p[i]+=(a[i]=='_');
}
dp(0,0,0) ;
dp(0,0,1) ;
vector<char> ans(n,'_') ;
for(int i=0;i<n;i++){
if(i) b[i]+=b[i-1] ;
cout << b[i] << " " ;
if(b[i]&&w[i]) ans[i]='?' ;
else if(b[i]) ans[i]='X' ;
}
string rans ;
for(char x : ans)rans+=x ;
return rans ;
}
# | 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... |