Submission #619650

#TimeUsernameProblemLanguageResultExecution timeMemory
619650Bench0310Paint By Numbers (IOI16_paint)C++17
100 / 100
372 ms160592 KiB
#include <bits/stdc++.h> #include "paint.h" using namespace std; typedef long long ll; const int N=200000; const int K=200; bool one[N+1][K+1][2]; bool two[N+2][K+2][2]; string solve_puzzle(string s,vector<int> c) { int n=s.size(); int k=c.size(); c.insert(c.begin(),0); s="$"+s; vector<int> wsum(n+1,0); for(int i=1;i<=n;i++) wsum[i]=wsum[i-1]+(s[i]=='_'); auto ws=[&](int l,int r)->int{return (wsum[r]-wsum[l-1]);}; one[0][0][1]=1; for(int i=1;i<=n;i++) { //extend for(int j=0;j<=k;j++) one[i][j][1]=((one[i-1][j][0]||one[i-1][j][1])&&(s[i]!='X')); //new block for(int j=1;j<=k;j++) if(i-c[j]>=0) one[i][j][0]=(one[i-c[j]][j-1][1]&&ws(i-c[j]+1,i)==0); } two[n+1][k+1][1]=1; for(int i=n;i>=1;i--) { //extend for(int j=1;j<=k+1;j++) two[i][j][1]=((two[i+1][j][0]||two[i+1][j][1])&&(s[i]!='X')); //new block for(int j=1;j<=k;j++) if(i+c[j]<=n+1) two[i][j][0]=(two[i+c[j]][j+1][1]&&ws(i,i+c[j]-1)==0); } vector<int> d(n+2,0); vector<bool> white(n+1,0); for(int i=1;i<=n;i++) { //white for(int j=0;j<=k;j++) if(one[i][j][1]&&two[i][j+1][1]) white[i]=1; //black for(int j=1;j<=k;j++) { if(one[i][j][0]&&two[i+1][j+1][1]) { d[i-c[j]+1]++; d[i+1]--; } } } int black=0; string res(n,'?'); for(int i=1;i<=n;i++) { black+=d[i]; if(white[i]&&black) res[i-1]='?'; else if(white[i]) res[i-1]='_'; else if(black) res[i-1]='X'; } return res; }
#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...