Submission #102893

#TimeUsernameProblemLanguageResultExecution timeMemory
102893daniel920712Paint By Numbers (IOI16_paint)C++14
100 / 100
1333 ms86420 KiB
#include <iostream> #include <stdio.h> #include <vector> #include <utility> #include <queue> #include "paint.h" using namespace std; bool Can[2][200005]={0}; int N,M; bool have[200005][105][2]={0}; bool can[200005][105][2]={0}; int How[200005]={0}; int how[200005]={0}; int Big[200005]; string a; vector < int > c; void F2() { int here,what,x,t; pair < pair < int ,int > , int > temp; queue < pair < pair < int ,int > , int > > all; all.push(make_pair(make_pair(0,0),1)); all.push(make_pair(make_pair(0,0),0)); can[N][M][0]=1; can[N][M][1]=1; while(!all.empty()) { temp=all.front(); all.pop(); here=temp.first.first; what=temp.first.second; x=temp.second; if(here==N) continue; if(have[here][what][x]) continue; have[here][what][x]=1; if(x==how[here]) continue; if(x==0) { if(what==M) continue; t=here+c[what]; if(t>N||what==M||How[t-1]-How[here]) continue; all.push(make_pair(make_pair(t,what+1),1)); } else { all.push(make_pair(make_pair(here+1,what),0)); all.push(make_pair(make_pair(here+1,what),1)); } } for(here=N-1;here>=0;here--) { for(what=M;what>=0;what--) { for(x=0;x<2;x++) { if(x==how[here]||!have[here][what][x]) continue; if(x==0) { if(what==M) continue; t=here+c[what]; if(t>N||what==M||How[t-1]-How[here]) continue; if(can[t][what+1][1]) { can[here][what][0]|=1; Can[0][here]|=1; Big[here]=max(Big[here],t-1); } } else { can[here][what][1]|=can[here+1][what][0]; can[here][what][1]|=can[here+1][what][1]; Can[1][here]|=can[here][what][1]; } } } } } string solve_puzzle(string s, vector < int > c) { int i,j,big=-1; a=s; ::c=c; 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; if(s[i]=='_') how[i]=0; else if(s[i]=='X') how[i]=1; else how[i]=2; } F2(); for(i=0;i<N;i++) { for(j=max(big+1,i);j<=Big[i];j++) Can[0][j]=1; big=max(big,Big[i]); } 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; }
#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...