Submission #65961

#TimeUsernameProblemLanguageResultExecution timeMemory
65961gs13068Paint By Numbers (IOI16_paint)C++17
100 / 100
223 ms54180 KiB
#include "paint.h" #include <cstdio> #include <cstdlib> int a[200002]; bool L[200002][111]; bool R[200002][111]; int yes[200002], no[200002]; std::string solve_puzzle(std::string s, std::vector<int> c) { int i, j; int n = s.size(), m = c.size(); for (i = 0; i < n; i++) a[i + 1] = a[i] + (s[i] == '_'); L[0][0] = true; for (i = 1; i <= n; i++) for (j = 0; j <= m; j++) { if (s[i - 1] != 'X' && L[i - 1][j]) { L[i][j] = true; continue; } if (j && i >= c[j - 1] && a[i] == a[i - c[j - 1]] && (j == 1 ? L[i - c[0]][0] : i > c[j - 1] && L[i - c[j - 1] - 1][j - 1] && s[i - c[j - 1] - 1] != 'X')) L[i][j] = true; } R[n + 1][m] = true; for (i = n; i >= 1; i--) for (j = m; j >= 0; j--) { if (j < m && i + c[j] <= n + 1 && a[i - 1] == a[i + c[j] - 1] && (j + 1 == m ? R[i + c[j]][j + 1] : i + c[j] < n + 1 && R[i + c[j] + 1][j + 1] && s[i + c[j] - 1] != 'X')) { R[i][j] = true; if (j ? i > 1 && L[i - 2][j] && s[i - 2] != 'X' : L[i - 1][0]) { yes[i - 1]++; yes[i + c[j] - 1]--; } continue; } if (s[i - 1] != 'X' && R[i + 1][j]) R[i][j] = true; } // for (j = 0; j <= m; j++, puts("")) for (i = 0; i <= n + 1; i++) printf("%d ", L[i][j]); puts(""); // for (j = 0; j <= m; j++, puts("")) for (i = 0; i <= n + 1; i++) printf("%d ", R[i][j]); puts(""); std::string res; for (i = 0; i < n; i++) { yes[i + 1] += yes[i]; if (s[i] != 'X') { for (j = 0; j <= m; j++) if (L[i][j] && R[i + 2][j]) break; no[i] = j <= m; } res.push_back(yes[i] && no[i] ? '?' : yes[i] ? 'X' : '_'); } return res; }
#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...