Submission #592240

#TimeUsernameProblemLanguageResultExecution timeMemory
592240EliasPaint By Numbers (IOI16_paint)C++17
90 / 100
1103 ms524288 KiB
#include <bits/stdc++.h> using namespace std; #include "paint.h" int n, k; vector<bool> hi; vector<int> cl; unordered_map<int, bool> dp; vector<int> wh, bl; vector<int> numWhite; bool checkWhite(int l, int r) { int cnt = numWhite[r - 1]; if (l) cnt -= numWhite[l - 1]; return cnt; } bool DP(int i, int j) { if (i <= 0) return j == 0; if (dp.count(i + (j << 20))) return dp[i + (j << 20)]; bool b = false; if (j > 0) { int size = cl[j - 1]; if (i >= size && (i == size || !hi[i - size - 1]) && !checkWhite(i - size, i)) { if (DP(i - size - 1, j - 1)) { b = true; if (i != n) bl[i]--; bl[i - size]++; if (i - size > 0) wh[i - size - 1]++; } } } if (!hi[i - 1]) { if (DP(i - 1, j)) { b = true; wh[i - 1]++; } } return dp[i + (j << 20)] = b; } string solve_puzzle(string s, vector<int> c) { n = s.size(); k = c.size(); cl = c; hi = vector<bool>(n); numWhite = vector<int>(n); for (int i = 0; i < n; i++) { numWhite[i] += numWhite[max(i - 1, 0)]; if (s[i] == 'X') hi[i] = true; if (s[i] == '_') numWhite[i]++; } wh = bl = vector<int>(n); DP(n, k); int black = 0; string out; for (int i = 0; i < n; i++) { black += bl[i]; if (black && wh[i]) out.push_back('?'); else if (black) out.push_back('X'); else out.push_back('_'); } return out; } #ifdef _DEBUG signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; string s; cin >> s; vector<int> blub(k); for (int &x : blub) cin >> x; cout << solve_puzzle(s, blub); } #endif
#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...