Submission #537904

#TimeUsernameProblemLanguageResultExecution timeMemory
537904timreizinPaint By Numbers (IOI16_paint)C++17
100 / 100
735 ms139216 KiB
#include "paint.h" using namespace std; string solve_puzzle(string s, vector<int> c) { int n = (int)s.size(), k = c.size(); vector dpWR(n + 1, vector(k + 1, false)), dpBR(n + 1, vector(k + 1, false)), dpWL(n + 2, vector(k + 1, false)), dpBL(n + 2, vector(k + 1, false)); vector<int> pref(n + 1); for (int i = 0; i < n; ++i) pref[i + 1] = pref[i] + (s[i] == '_'); dpWR[0][0] = 1; for (int i = 1; i <= n; ++i) { for (int j = 0; j <= k; ++j) { if (s[i - 1] != '_' && j != k && i - c[j] >= 0 && pref[i] - pref[i - c[j]] == 0) dpBR[i][j] = dpWR[i - c[j]][j]; if (s[i - 1] != 'X') dpWR[i][j] = dpWR[i - 1][j] | (j == 0 ? 0 : dpBR[i - 1][j - 1]); } } dpWL[n + 1][k] = 1; for (int i = n; i >= 1; --i) { for (int j = 0; j <= k; ++j) { if (s[i - 1] != '_' && j != k && i + c[j] <= n + 1 && pref[i + c[j] - 1] - pref[i - 1] == 0) dpBL[i][j] = dpWL[i + c[j]][j + 1]; if (s[i - 1] != 'X') dpWL[i][j] = dpWL[i + 1][j] | dpBL[i + 1][j]; } } vector<vector<int>> works(k); for (int i = 1; i <= n; ++i) for (int j = 0; j < k; ++j) if (i + c[j] - 1 <= n && dpBL[i][j] && dpBR[i + c[j] - 1][j]) works[j].push_back(i); vector<int> inds(k); for (int i = 1; i <= n; ++i) { bool checkW = false, checkB = false; for (int j = 0; j <= k; ++j) { checkW |= dpWR[i][j] && dpWL[i][j]; if (j < k) { while (inds[j] != works[j].size() && works[j][inds[j]] < i + 1 - c[j]) ++inds[j]; if (inds[j] != works[j].size()) checkB |= works[j][inds[j]] <= i; } } if (checkB && checkW) s[i - 1] = '?'; else if (checkB) s[i - 1] = 'X'; else s[i - 1] = '_'; } return s; }

Compilation message (stderr)

paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:40:32: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |                 while (inds[j] != works[j].size() && works[j][inds[j]] < i + 1 - c[j]) ++inds[j];
paint.cpp:41:29: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |                 if (inds[j] != works[j].size()) checkB |= works[j][inds[j]] <= i;
#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...