Submission #69138

#TimeUsernameProblemLanguageResultExecution timeMemory
69138mr_bananaPaint By Numbers (IOI16_paint)C++17
100 / 100
527 ms22460 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; const int MN=2e5+20,MK=100+10; bitset<MK> dp[2][MN]; bitset<MK> dp1[2][MN]; int bef[MN],aft[MN]; int a[MN]; bool canb[MN],canw[MN]; string solve_puzzle(string s, vector<int> c) { int n=s.size(),k=c.size(); for(int i=0;i<n;i++){ if(s[i]=='.'){ a[i+1]=-1; } if(s[i]=='X'){ a[i+1]=1; } if(a[i+1]==0){ bef[i+1]=i+1; } else{ bef[i+1]=bef[i]; } } aft[n+1]=n+1; for(int i=n;i>0;i--){ if(a[i]==0){ aft[i]=i; } else{ aft[i]=aft[i+1]; } } dp1[0][0][0]=1; for(int i=1;i<=n;i++){ for(int j=0;j<=k;j++){ if(j>0 && bef[i]<=i-c[j-1]){ dp1[1][i][j]=(dp1[1][i][j]|dp1[0][i-c[j-1]][j-1]); } if(a[i]!=1){ dp1[0][i][j]=(dp1[0][i][j]|dp1[0][i-1][j]|dp1[1][i-1][j]); } } } dp[0][n+1][k+1]=1; for(int i=n;i>0;i--){ for(int j=1;j<=k+1;j++){ if(j<=k && aft[i]>=i+c[j-1]){ dp[1][i][j]=(dp[1][i][j]|dp[0][i+c[j-1]][j+1]); } if(a[i]!=1){ dp[0][i][j]=(dp[0][i][j]|dp[0][i+1][j]|dp[1][i+1][j]); } } } for(int i=1;i<=n;i++){ for(int j=0;j<=k;j++){ if(dp[0][i][j+1]&dp1[0][i][j]){ canw[i]=1; } } } for(int j=0;j<=k;j++){ int cur=0; for(int i=1;i<=n;i++){ if(dp[1][i][j+1]&dp1[0][i-1][j]){ cur=c[j]; } if(cur>0){ canb[i]=1; } cur--; } } string ans; for(int i=1;i<=n;i++){ if(canb[i]&canw[i]){ ans+='?'; } else if(canb[i]){ ans+='X'; } else if(canw[i]){ ans+='_'; } } 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...