Submission #637261

#TimeUsernameProblemLanguageResultExecution timeMemory
637261ggohPaint By Numbers (IOI16_paint)C++14
100 / 100
1047 ms113704 KiB
#include "paint.h" #include<bits/stdc++.h> using namespace std; #define sz(v) ((int)(v).size()) typedef long long lint; int dif[200002][20]; int D[200002][102]; int C[200002]; int sum[200002]; string S; int n,m; int f(int p,int q) { int ret1=0,ret2=0,ret=0; if(D[p][q])return D[p][q]; if(p==n) { if(q==m)ret=1; else ret=-1; return D[p][q]=ret; } if(S[p]=='X'||S[p]=='.') { if(q==m || p+C[q]-1>=n)ret1=-1; else { if(sum[p+C[q]]-sum[p]>0)ret1=-1; if(ret1!=-1) { if(S[p+C[q]]=='X')ret1=-1; else ret1=f(p+C[q]+1,q+1); } } if(ret1==1) { dif[p][1]++; dif[p+C[q]][1]--; dif[p+C[q]][0]++; dif[p+C[q]+1][0]--; } } if(S[p]=='_'||S[p]=='.') { ret2=f(p+1,q); if(ret2==1) { dif[p][0]++; dif[p+1][0]--; } } if(ret1==1||ret2==1)ret=1; else ret=-1; if(S[p]=='X')return D[p][q]=ret1; else if(S[p]=='_')return D[p][q]=ret2; else return D[p][q]=ret; } string solve_puzzle(string s, vector<int> c) { string ans; S=s; S+='_'; n=S.length(); for(int i=0;i<n;i++)sum[i+1]=sum[i]+(S[i]=='_'?1:0); m=sz(c); for(int i=0;i<m;i++)C[i]=c[i]; f(0,0); for(int i=1;i<n;i++) { dif[i][1]+=dif[i-1][1]; dif[i][0]+=dif[i-1][0]; } for(int i=0;i<n-1;i++) { if(dif[i][0] && dif[i][1])ans+='?'; else if(dif[i][0])ans+='_'; else ans+='X'; } return ans; }
#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...