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 "paint.h"
#include <bits/stdc++.h>
using namespace std;
bool dp[200005][105],dp2[200005][105];
int b[200005],w[200005],ims[200005];
string solve_puzzle(string s, vector<int> c) {
s='_'+s;
s+='_';
int n=s.size(),k=c.size();
for(int i=0;i<n;i++){
if(s[i]=='X')b[i]++;
if(i>0)b[i]+=b[i-1];
if(s[i]=='_')w[i]++;
if(i>0)w[i]+=w[i-1];
}
dp[0][0]=true;
for(int i=0;i<n-1;i++){
for(int j=0;j<=k;j++){
if(!dp[i][j])continue;
if(s[i+1]!='X')dp[i+1][j]=true;
if(j<k&&i+c[j]<n-1&&w[i+c[j]]-w[i]==0&&s[i+c[j]+1]!='X')dp[i+c[j]+1][j+1]=true;
}
}
dp2[n-1][k]=true;
for(int i=n-1;i>0;i--){
for(int j=k;j>=0;j--){
if(!dp2[i][j])continue;
if(s[i-1]!='X')dp2[i-1][j]=true;
if(j>0&&i-c[j-1]>0&&w[i-1]-w[i-c[j-1]-1]==0&&s[i-c[j-1]-1]!='X')dp2[i-c[j-1]-1][j-1]=true;
}
}
string ans;
for(int i=0;i<n;i++)ans+='.';
for(int i=0;i<n;i++){
for(int j=0;j<=k;j++){
if(dp[i][j]&&dp2[i][j])ans[i]='_';
}
}
for(int i=0;i<n-1;i++){
for(int j=0;j<=k;j++){
if(!dp[i][j])continue;
if(j<k&&i+c[j]<n-1&&w[i+c[j]]-w[i]==0&&s[i+c[j]+1]!='X'&&dp2[i+c[j]+1][j+1]){
ims[i+1]++;
ims[i+c[j]+1]--;
}
}
}
for(int i=0;i<n;i++){
if(i>0)ims[i]+=ims[i-1];
if(ims[i]>0){
if(ans[i]=='_')ans[i]='?';
else ans[i]='X';
}
}
return ans.substr(1,n-2);
}
# | 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... |