제출 #619648

#제출 시각아이디문제언어결과실행 시간메모리
619648Bench0310Paint By Numbers (IOI16_paint)C++17
90 / 100
568 ms524288 KiB
#include <bits/stdc++.h> #include "paint.h" using namespace std; typedef long long ll; 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]);}; vector one(n+1,vector(k+1,vector(2,bool(0)))); 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); } vector two(n+2,vector(k+2,vector(2,bool(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...