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 <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include "paint.h"
using namespace std;
bool Can[2][200005]={0};
int N,M,ans=0;
bool have[200005][105][2]={0};
bool can[200005][105][2]={0};
int How[200005]={0};
int now=1;
int Big[200005];
int F(int here,int what,int x,string &a,vector < int > &c)
{
int A,b,i;
if(have[here][what][x]) return can[here][what][x];
else if(here==N&&what==M) return 1;
else if(here==N) return 0;
else
{
if(x==0&&a[here]=='_'||x==1&&a[here]=='X') return 0;
if(x==0)
{
if(here+c[what]>N) return 0;
if(what==M) return 0;
if(How[here+c[what]-1]-How[here]||a[here]=='_') return 0;
have[here][what][x]=1;
A=F(here+c[what],what+1,1,a,c);
can[here][what][x]=A;
if(A)
{
//printf("%d %d %d\n",here,what,A);
Big[here]=max(Big[here],here+c[what]-1);
}
}
else
{
have[here][what][x]=1;
A=F(here+1,what,0,a,c);
b=F(here+1,what,1,a,c);
can[here][what][x]=A||b;
//printf("%d %d %d %d\n",here,what,A,b);
Can[x][here]=can[here][what][x]||Can[x][here];
}
}
return can[here][what][x];
}
string solve_puzzle(string s, vector < int > c)
{
int i,j,big=-1;
N=s.length(),M=c.size();
for(i=0;i<N;i++)
{
if(i) How[i]=How[i-1];
How[i]+=(s[i]=='_');
Big[i]=-1;
}
F(0,0,0,s,c);
F(0,0,1,s,c);
for(i=0;i<N;i++)
{
//printf("%d ",Big[i]);
for(j=max(big,i);j<=max(big,Big[i]);j++) Can[0][j]=1;
big=max(big,Big[i]);
}
//printf("\n");
for(i=0;i<N;i++)
{
if(Can[0][i]==0) s[i]='_';
else if(Can[1][i]==0) s[i]='X';
else s[i]='?';
}
return s;
}
Compilation message (stderr)
paint.cpp: In function 'int F(int, int, int, std::__cxx11::string&, std::vector<int>&)':
paint.cpp:23:16: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if(x==0&&a[here]=='_'||x==1&&a[here]=='X') return 0;
~~~~^~~~~~~~~~~~~~
paint.cpp:17:13: warning: unused variable 'i' [-Wunused-variable]
int A,b,i;
^| # | 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... |