Submission #102753

#TimeUsernameProblemLanguageResultExecution timeMemory
102753daniel920712Paint By Numbers (IOI16_paint)C++14
90 / 100
857 ms525312 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[1000005]; 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) { 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; //printf("%d %d %d\n",here,what,x); if(Find(here,here+c[what]-1,0)) { //printf("%d %d %d\n",here,what,x); return 0; } //printf("%d %d %d\n",here,what,x); have[here][what][x]=1; A=F(here+c[what],what+1,1,a,c); can[here][what][x]=A; //printf("%d %d %d\n",here,what,x); if(A) change(here,here+c[what]-1,0); //printf("%d %d %d\n",here,what,x); } 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); 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:112: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...