Submission #102748

#TimeUsernameProblemLanguageResultExecution timeMemory
102748daniel920712Paint By Numbers (IOI16_paint)C++14
0 / 100
2041 ms384 KiB
#include <iostream>
#include <stdio.h>
#include <vector>
#include "paint.h"
using namespace std;
int con[200005]={0};
int Can[5][200005]={0};
//int Canx[200005]={0};
int N,M,ans=0;
bool have[200005][105][5]={0};
int can[200005][105][5]={0};
struct A
{
    int l,r;
    int nxl,nxr;
    int have_Y;
    int can_X;
}Node[10000005];
int now=1;
void build(int l,int r,int here,string &a)
{
    Node[here].l=l;
    Node[here].r=r;
    Node[here].can_X=0;
    if(l==r)
    {
        Node[here].have_Y=(a[l]=='_');
        return ;
    }
    Node[here].nxl=now++;
    Node[here].nxr=now++;
    build(l,(l+r)/2,Node[here].nxl,a);
    build((l+r)/2+1,r,Node[here].nxr,a);
    Node[here].have_Y=Node[Node[here].nxl].have_Y||Node[Node[here].nxr].have_Y;
}
bool Find(int l,int r,int here)
{
    if(l==Node[here].l&&r==Node[here].r) return Node[here].have_Y;
    if(l>(Node[here].l+Node[here].r)/2) return Find(l,r,Node[here].nxr);
    if(r<=(Node[here].l+Node[here].r)/2) return Find(l,r,Node[here].nxl);
    return Find(l,(Node[here].l+Node[here].r)/2,Node[here].nxl)||Find((Node[here].l+Node[here].r)/2+1,r,Node[here].nxr);
}
bool Find_2(int where,int here)
{
    if(where==Node[here].l&&where==Node[here].r) return Node[here].can_X;
    if(where>(Node[here].l+Node[here].r)/2) return Find_2(where,Node[here].nxr)||Node[here].can_X;
    if(where<=(Node[here].l+Node[here].r)/2) return Find_2(where,Node[here].nxl)||Node[here].can_X;
}
void change(int l,int r,int here)
{
    if(l==Node[here].l&&r==Node[here].r)
    {
        Node[here].can_X=1;
        return;
    }
    if(l>(Node[here].l+Node[here].r)/2)
    {
        change(l,r,Node[here].nxr);
        return;
    }
    if(r<=(Node[here].l+Node[here].r)/2)
    {
        change(l,r,Node[here].nxl);
        return;
    }
    change(l,(Node[here].l+Node[here].r)/2,Node[here].nxl);
    change((Node[here].l+Node[here].r)/2+1,r,Node[here].nxr);
}
int F(int here,int what,int x,string &a,vector < int > &c)
{
    //printf("%d %d %d\n",here,what,x);
    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(Find(here,here+c[what]-1,0)) return 0;

            have[here][what][x]=1;
            A=F(here+c[what],what+1,1,a,c);
            can[here][what][x]=A;
            if(A) change(here,here+c[what]-1,0);

        }
        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;
            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;
    N=s.length(),M=c.size();
    build(0,N-1,0,s);
    //printf("%d %d\n",N,M);
    //all[M]=0;
    //for(i=M-1;i>=0;i--) all[i]=all[i+1]+c[i]+1;
    F(0,0,0,s,c);
    F(0,0,1,s,c);
    for(i=0;i<N;i++)
    {
        if(Find_2(i,0)==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:78:16: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
         if(x==0&&a[here]=='_'||x==1&&a[here]=='X') return 0;
            ~~~~^~~~~~~~~~~~~~
paint.cpp:72:13: warning: unused variable 'i' [-Wunused-variable]
     int A,b,i;
             ^
paint.cpp: In function 'std::__cxx11::string solve_puzzle(std::__cxx11::string, std::vector<int>)':
paint.cpp:104:11: warning: unused variable 'j' [-Wunused-variable]
     int i,j;
           ^
paint.cpp: In function 'bool Find_2(int, int)':
paint.cpp:48:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...