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>
#include "paint.h"
using namespace std;
int pref[300001][101];
int suf[300001][101];
string solve_puzzle(string s, vector<int> c){
int n = s.size() , k = c.size();
pref[0][0] = 1;
suf[n+1][k] = 1;
suf[n+2][k] = 1;
s = '0'+s;
int wi[n+1] = {0},bl[n+1] = {0};
int nah[n+1] = {0},part[n+2] = {0};
for(int i = 0;i<=n;i++){
wi[i] = 0;
}
for(int i = 1;i<=n;i++){
wi[i] = wi[i-1];
bl[i] = bl[i-1];
if(s[i]=='_'){
wi[i] = wi[i-1]+1;
}if(s[i]=='X'){
bl[i] = bl[i-1]+1;
}
}
for(int i = 1;i<=n;i++){
for(int j = 0;j<=k;j++){
if(s[i]=='.'||s[i]=='_'){
pref[i][j] |= pref[i-1][j];
}if(j>=1&&c[j-1]<=i&&wi[i]-wi[i-c[j-1]]==0&&(i-c[j-1]<=0||s[i-c[j-1]]!='X')){
//cout<<i<<"hhh "<<j<<endl;
if(i-c[j-1]==0){
if(j==1)pref[i][j] |= 1;
}
else pref[i][j] |= pref[i-c[j-1]-1][j-1];
}
}
}
for(int i = n;i>=1;i--){
for(int j = 0;j<=k;j++){
if(s[i]=='.'||s[i]=='_'){
suf[i][j] |= suf[i+1][j];
}if(j<k&&c[j]<=(n-i+1)&&wi[i+c[j]-1]-wi[i-1]==0&&(i+c[j]>n||s[i+c[j]]!='X')){
if(i+c[j]==n+1){
if(j==k-1)suf[i][j] = 1;
}
else suf[i][j] |= suf[i+c[j]+1][j+1];
}
}
}
for(int i = 1;i<=n;i++){
bool ss = 0;
for(int j = 0;j<=k;j++){
if(pref[i-1][j]&&suf[i+1][j]&&s[i]!='X'){
ss = 1;
}
}
if(ss)nah[i]|=1;
}
for(int i = 1;i<=n;i++){
for(int j = 0;j<k;j++){
if((i==1?(j==0):(pref[i-2][j]&&s[i-1]!='X'))&&i+c[j]-1<=n&&suf[i+c[j]+1][j+1]&&wi[i+c[j]-1]-wi[i-1]==0&&(i+c[j]>n||s[i+c[j]]!='X')){
if(i+c[j]>n){
if(j+1==k){
part[i]++;
part[i+c[j]]--;
}
}else{
part[i]++;
part[i+c[j]]--;
}
}
}
}
for(int i = 1;i<=n;i++){
part[i]+=part[i-1];
if(part[i])nah[i]|=2;
}
string ans;
for(int i = 1;i<=n;i++){
if(nah[i]==3)ans+='?';
if(nah[i]==1)ans+='_';
if(nah[i]==2)ans+='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... |