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;
#include "paint.h"
#define ll long long
#define pb push_back
const int N = 2e5 + 2;
//const int S_MAX_LEN = 200 * 1000;
//char buf[S_MAX_LEN + 1];
int M[N][201],a[201],nex[N],t[N],zer[N],n,k;
string s,ans;
int f(int i, int j){
//cout << i << " " << j << " " << h << " aa\n";
if(i >= n) return j==k;
int &r = M[i][j];
if(r != -1) return r;
r = 0;
if(j < k && i+a[j] <= nex[i] && s[ i+a[j] ] != 'X') {
r |= f(i+a[j]+1,j+1);
//cout << i << " " << j << " " << r << " zz\n";
if(r){
zer[ i+a[j] ] = 1;
t[i]++; t[ i+a[j] ]--; }
}
if(s[i] != 'X'){
int t = f(i+1,j);
r |= t;
if(t) zer[i]=1;
}
return r;
}
string solve_puzzle(string ss, vector <int> aa){
int i;
s = ss;
n = s.size();
s.pb('.');
k = aa.size();
for(i=0;i<k;i++) a[i] = aa[i];
nex[n] = n;
for(i=n-1; i>=0; i--){
nex[i] = nex[i+1];
if(s[i] == '_') nex[i] = i;
}
memset(M , -1 , sizeof M);
f(0,0);
int x = 0;
ans.resize(n);
for(i=0;i<n;i++){
x += t[i];
if(s[i] != '.'){
ans[i] = s[i];
continue;
}
if(zer[i] && x>0){
ans[i] = '?';
}
else if(zer[i]) ans[i] = '_';
else ans[i] = 'X';
}
return ans;
}
# | 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... |