제출 #71354

#제출 시각아이디문제언어결과실행 시간메모리
71354hamzqq9Paint By Numbers (IOI16_paint)C++14
100 / 100
683 ms211796 KiB
#include "paint.h" #include<bits/stdc++.h> #define st first #define nd second #define pb push_back #define ppb pop_back #define umax(x,y) x=max(x,y) #define umin(x,y) x=min(x,y) #define ll long long #define ii pair<int,int> #define iii pair<int,ii> #define sz(x) ((int) x.size()) #define orta ((bas+son)>>1) #define all(x) x.begin(),x.end() #define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" " #define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar() #define pw(x) (1<<(x)) #define inf 2000000000 #define MOD 1000000007 #define N 200005 #define MAX 10000006 #define K 105 #define LOG 30 #define KOK 200 using namespace std; int n,k; bool dp[2][K][N],_[N]; int predp[2][K][N],ok[2][N],px[N],nr[2][N],pre_[2][N]; vector<int> c; string s; void find_pos() { // try empty for(int i=1;i<=n;i++) { if(s[i]=='.') { bool okey=false; for(int j=0;j<=k;j++) { if(predp[0][j][i-1]-(nr[0][i-1]-1<0?0:predp[0][j][nr[0][i-1]-1])>0 && predp[1][k-j][n-i]-(nr[1][n-i]-1<0?0:predp[1][k-j][nr[1][n-i]-1])>0) { okey=true; } } if(okey) _[i]=1; } } // try X for(int i=n;i>=1;i--) { if(dp[0][k][i]) ok[0][i]++,ok[0][i+1]--; if(s[i]=='X') break ; } for(int i=k;i>=1;i--) { for(int j=1;j<=n;j++) { ok[0][j]+=ok[0][j-1]; if(ok[0][j] && dp[0][i][j] && s[j+1]!='X') { px[j-c[i]+1]++; px[j+1]--; ok[1][j-c[i]]--; ok[1][nr[0][max(0,j-c[i]-1)]]++; } } for(int j=0;j<=n;j++) { ok[0][j]=ok[1][j]; ok[1][j]=0; } } px[0]=0; for(int i=1;i<=n;i++) { px[i]+=px[i-1]; if(s[i]!='.') continue ; if(px[i] && _[i]) { s[i]='?'; } else if(px[i]) s[i]='X'; else s[i]='_'; } } void solve(int w) { for(int i=0;i<=n && !nr[w][i];i++) dp[w][0][i]=1; predp[w][0][0]=dp[w][0][0]; for(int i=1;i<=n;i++) predp[w][0][i]=predp[w][0][i-1]+dp[w][0][i]; for(int i=1;i<=k;i++) { for(int j=1;j<=n;j++) { if(c[i]>j) continue ; if(pre_[w][j]-pre_[w][j-c[i]]) continue ; if(s[j-c[i]]=='X') continue ; if(j-c[i]-1>=0) { dp[w][i][j]=(predp[w][i-1][j-c[i]-1]-(nr[w][j-c[i]-1]-1<0?0:predp[w][i-1][nr[w][j-c[i]-1]-1])>0); } else if(i==1) dp[w][i][j]=1; } predp[w][i][0]=dp[w][i][0]; for(int j=1;j<=n;j++) predp[w][i][j]=predp[w][i][j-1]+dp[w][i][j]; } /*for(int i=1;i<=k;i++) { for(int j=0;j<=n;j++) { printf("%d %d %d %d\n",w,i,j,dp[w][i][j]); } }*/ } void fpre(int w) { for(int i=1;i<=n;i++) { pre_[w][i]=pre_[w][i-1]+(s[i]=='_'); } } void fnears(int w) { int near=0; for(int i=1;i<=n;i++) { if(s[i]=='X') near=i; nr[w][i]=near; } } void pre_cal() { n=sz(s)-2; k=sz(c)-2; fnears(0); fpre(0); reverse(all(s)); reverse(all(c)); fnears(1); fpre(1); reverse(all(s)); reverse(all(c)); } void solve_dp() { solve(0); reverse(all(s)); reverse(all(c)); solve(1); reverse(all(s)); reverse(all(c)); } std::string solve_puzzle(std::string s, std::vector<int> c) { ::s=" "+s+" "; ::c.pb(0); for(int i=0;i<sz(c);i++) ::c.pb(c[i]); ::c.pb(0); pre_cal(); solve_dp(); find_pos(); string result; for(int i=1;i<=n;i++) result.pb(::s[i]); return result; }
#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...