Submission #1112868

#TimeUsernameProblemLanguageResultExecution timeMemory
1112868LuvidiPaint By Numbers (IOI16_paint)C++17
90 / 100
481 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)); for(int i=0;i<=n+1;i++){ if(s[i]=='X')break; dp[i][0]=1; } for(int i=1;i<=n+1;i++){ for(int j=1;j<=n2+1;j++){ if(s2[j]=='X'){ if(s[i]!='_')dp[i][j]|=dp[i-1][j-1]; }else{ if(s[i]!='X')dp[i][j]|=dp[i-1][j]||dp[i-1][j-1]; } } } bool dp2[n+2][n2+2]; memset(dp2,0,sizeof(dp2)); for(int i=n+1;i>-1;i--){ if(s[i]=='X')break; dp2[i][n2+1]=1; } for(int i=n;i>-1;i--){ for(int j=n2;j>-1;j--){ if(s2[j]=='X'){ if(s[i]!='_')dp2[i][j]|=dp2[i+1][j+1]; }else{ if(s[i]!='X')dp2[i][j]|=dp2[i+1][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...