This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma once
#include<bits/stdc++.h>
using namespace std;
int k=0;
string s;
vector<int> c;
int n;
int const N=105;
int pre[N][N];
int suf[N][N];
bool check(int a,int b,int l,int r){
if(a>b)
return 1;
int p=a;
int ind=l;
while(p<=b){
if(ind+c[p]>(r+1))
return 0;
bool bl=1;
for (int i = ind; i < ind+c[p]; ++i)
if(s[i]=='_')
bl=0;
if(bl){
ind+=c[p];
p++;
if(p<=b)
ind++;
}
else
ind++;
}
return 1;
}
void preprocess(){
for (int i = -1; i < n; ++i)
for (int j = -1; j < k; ++j)
pre[i+1][j+1]=check(0,j,0,i);
for (int i = n; i>=0; --i)
for(int j=k;j>=0;j--)
suf[i][j]=check(j,k-1,i,n-1);
}
string solve_puzzle(string ss, vector<int> cc){
k=cc.size();
c=cc;
s=ss;
n=s.length();
preprocess();
for (int i = 0; i < n; ++i)
{
if(s[i]=='_')
continue;
//if i put a _ here then check that is there a valid solution
s[i]='X';
for (int j = -1; j < k; ++j)
if(pre[i][j+1] && suf[i+1][j+1]){
s[i]='?';
break;
}
}
int tot=0;
for (int i = 0; i < k; ++i)
tot+=c[i];
for (int i = 0; i < n; ++i)
{
if(s[i]=='X')
continue;
int sm=0;
bool bb=1;
for (int j = 0; j < k; ++j)
{
for (int f = max(0,(i-c[j])+1); f <=i; ++f)
{
if(f+c[j]>n)
break;
bool bl=0;
for(int ii=f;ii<f+c[j];ii++)
if(s[ii]=='_'){
bl=1;
break;
}
if(bl)
continue;
if(pre[f-(j>0)][j] && suf[f+c[j]+(j<k-1)][j+1]){
bb=0;
break;
}
}
if(bb==0)
break;
sm+=c[j];
}
if(bb)
s[i]='_';
}
return s;
}
Compilation message (stderr)
paint.cpp:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |