Submission #960012

#TimeUsernameProblemLanguageResultExecution timeMemory
960012LucaLucaMPaint By Numbers (IOI16_paint)C++17
100 / 100
220 ms84376 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 + 2; bool pref[NMAX + 1][KMAX + 1][2]; bool suff[NMAX + 1][KMAX + 1][2]; int sumX[NMAX + 1]; int sum_[NMAX + 1]; int worksX[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, '.'); 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 + 1; j++) { pref[i][j][0] = pref[i][j][1] = false; } if (s[i] == 'X') { for (int j = 0; j <= k + 1; 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 + 1; 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 + 1; 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)); } } } } suff[n + 1][k + 1][0] = suff[n + 1][k + 1][1] = true; for (int i = n; i > 0; i--) { for (int j = 0; j <= k + 1; j++) { suff[i][j][0] = suff[i][j][1] = false; } if (s[i] == 'X') { for (int j = 0; j <= k + 1; j++) { if (j != 0 && i + c[j] <= n + 1) { suff[i][j][1] |= (suff[i + c[j]][j + 1][0] & makeX(i, i + c[j] - 1)); } } } else if (s[i] == '_') { for (int j = 0; j <= k + 1; j++) { suff[i][j][0] |= suff[i + 1][j][0]; suff[i][j][0] |= suff[i + 1][j][1]; } } else { for (int j = 0; j <= k + 1; j++) { if (j != 0 && i + c[j] <= n + 1) { suff[i][j][1] |= (suff[i + c[j]][j + 1][0] & makeX(i, i + c[j] - 1)); } } for (int j = 0; j <= k + 1; j++) { suff[i][j][0] |= suff[i + 1][j][0]; suff[i][j][0] |= suff[i + 1][j][1]; } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { if (i + c[j] <= n + 1 && pref[i - 1][j - 1][0] && suff[i + c[j]][j + 1][0] && makeX(i, i + c[j] - 1)) { worksX[i]++; worksX[i + c[j]]--; } } } for (int i = 1; i <= n; i++) { worksX[i] += worksX[i - 1]; } for (int i = 1; i <= n; i++) { if (s[i] != '.') { answer[i - 1] = s[i]; continue; } bool works_ = false; /// calculez works_ for (int j = 0; j <= k; j++) { if ((pref[i - 1][j][0] || pref[i - 1][j][1]) && (suff[i + 1][j + 1][0] || suff[i + 1][j + 1][1])) { works_ = true; } } if (worksX[i] && works_) { answer[i - 1] = '?'; } else if (worksX[i]) { answer[i - 1] = 'X'; } else { answer[i - 1] = '_'; } } 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...