Submission #1112870

#TimeUsernameProblemLanguageResultExecution timeMemory
1112870LuvidiPaint By Numbers (IOI16_paint)C++17
90 / 100
514 ms524288 KiB
#include "paint.h" #include <cstdlib> #include <bits/stdc++.h> using namespace std; std::string solve_puzzle(std::string s, std::vector<int> c) { int n=s.size(),k=c.size(); string s2="_"; for(int i=0;i<k;i++){ while(c[i]--)s2+='X'; if(i+1<k)s2+='_'; else s2+='_'; } s="_"+s+"_"; int n2=s2.size()-2; bool dp[n+2][n2+2]; memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int i=0;i<=n+1;i++){ for(int j=0;j<=n2+1;j++){ if(s2[j]=='X'){ if(s[i]!='_'){ if(i)dp[i][j]|=dp[i-1][j-1]; } }else{ if(s[i]!='X'){ if(i)dp[i][j]|=dp[i-1][j]; if(i&&j)dp[i][j]|=dp[i-1][j-1]; } } } } bool dp2[n+2][n2+2]; memset(dp2,0,sizeof(dp2)); dp2[n+1][n2+1]=1; for(int i=n+1;i>-1;i--){ for(int j=n2+1;j>-1;j--){ if(s2[j]=='X'){ if(s[i]!='_'){ if(i<=n)dp2[i][j]|=dp2[i+1][j+1]; } }else{ if(s[i]!='X'){ if(i<=n)dp2[i][j]|=dp2[i+1][j]; if(i<=n&&j<=n2)dp2[i][j]|=dp2[i+1][j+1]; } } } } string ans; for(int i=1;i<=n;i++){ bool b=0,w=0; for(int j=0;j<=n2+1;j++){ if(s2[j]=='X')b|=dp[i][j]&&dp2[i][j]; else w|=dp[i][j]&&dp2[i][j]; } if(b&&w)ans+="?"; else if(b)ans+="X"; else 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...