Submission #960007

#TimeUsernameProblemLanguageResultExecution timeMemory
960007LucaLucaMPaint By Numbers (IOI16_paint)C++17
80 / 100
2057 ms4696 KiB
#include "paint.h" #include <cstdlib> #include <functional> #include <iostream> #include <cassert> #define debug(x) #x << " = " << x << '\n' const int NMAX = 2e5 + 2; const int KMAX = 100; bool pref[NMAX + 1][KMAX + 1][2]; bool suff[NMAX + 1][KMAX + 1][2]; int sumX[NMAX + 1]; int sum_[NMAX + 1]; bool makeX(int l, int r) { return sum_[r] - sum_[l - 1] == 0; } bool make_(int l, int r) { return sumX[r] - sumX[l - 1] == 0; } std::string solve_puzzle(std::string s, std::vector<int> c) { int n = (int) s.size(); int k = (int) c.size(); s = '$' + s; c.insert(c.begin(), 0); std::string answer(n, '.'); std::function<void()> recalc = [&] () -> void { for (int i = 1; i <= n; i++) { sumX[i] = sumX[i - 1] + (s[i] == 'X'? +1 : 0); sum_[i] = sum_[i - 1] + (s[i] == '_'? +1 : 0); } pref[0][0][0] = pref[0][0][1] = true; for (int i = 1; i <= n; i++) { for (int j = 0; j <= k; j++) { pref[i][j][0] = pref[i][j][1] = false; } if (s[i] == 'X') { for (int j = 0; j <= k; j++) { if (j != 0 && i - c[j] >= 0) { pref[i][j][1] |= (pref[i - c[j]][j - 1][0] & makeX(i - c[j] + 1, i)); } } } else if (s[i] == '_') { for (int j = 0; j <= k; j++) { pref[i][j][0] |= pref[i - 1][j][0]; pref[i][j][0] |= pref[i - 1][j][1]; } } else { for (int j = 0; j <= k; j++) { pref[i][j][0] |= pref[i - 1][j][0]; pref[i][j][0] |= pref[i - 1][j][1]; if (j != 0 && i - c[j] >= 0) { pref[i][j][1] |= (pref[i - c[j]][j - 1][0] & makeX(i - c[j] + 1, i)); } } } } }; std::function<bool()> works = [&] () -> bool { return pref[n][k][0] | pref[n][k][1]; }; recalc(); assert(works()); for (int i = 1; i <= n; i++) { if (s[i] != '.') { answer[i - 1] = s[i]; continue; } bool worksX, works_; s[i] = 'X'; recalc(); worksX = works(); s[i] = '_'; recalc(); works_ = works(); // if (i == 3) { // std::cout << debug(works_) << debug(n) << debug(k); // std::cout << debug(pref[n][2][0]); // } s[i] = '.'; if (worksX && works_) { answer[i - 1] = '?'; } else if (worksX) { answer[i - 1] = 'X'; } else { answer[i - 1] = '_'; } } // std::cout << debug(s) << '\n'; return answer; } /** .......... 2 3 4 ........ 2 3 4 ..._._.... 1 3 .X........ 1 3 **/
#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...