Submission #226258

#TimeUsernameProblemLanguageResultExecution timeMemory
226258staniewzkiPaint By Numbers (IOI16_paint)C++17
100 / 100
536 ms8644 KiB
#include<bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define FOR(i, a, b) for(int i = a; i <= b; i++) #include "paint.h" string solve_puzzle(string s, vector<int> c) { int n = size(s), k = size(c); vector<int> w(n); REP(i, n) w[i] = (s[i] == '_') + (i != 0 ? w[i - 1] : 0); auto get = [&](int l, int r) { return w[r] - (l != 0 ? w[l - 1] : 0); }; vector<vector<bool>> suff(k + 1, vector<bool>(n + 1)); suff[k][n] = true; for(int i = k; i >= 0; i--) { for(int j = n - 1; j >= 0; j--) { if(s[j] != 'X' && suff[i][j + 1]) suff[i][j] = true; if(i < k) { int r = j + c[i] - 1; if(n <= r || get(j, r)) continue; if(i < k - 1 && (n <= r + 1 || s[r + 1] == 'X')) continue; if(suff[i + 1][(i < k - 1 ? r + 1 : r) + 1]) suff[i][j] = true; } } } vector<int> f(n + 1), e(n + 1); vector<vector<bool>> pref(k + 1, vector<bool>(n + 1)); pref[0][0] = true; REP(i, k + 1) REP(j, n) { if(!pref[i][j]) continue; if(s[j] != 'X') { pref[i][j + 1] = true; if(suff[i][j + 1]) e[j] = true; } if(i < k) { int r = j + c[i] - 1; if(n <= r || get(j, r)) continue; if(i < k - 1 && (n <= r + 1 || s[r + 1] == 'X')) continue; int p = (i < k - 1 ? r + 1 : r); pref[i + 1][p + 1] = true; if(suff[i + 1][p + 1]) { f[j]++, f[r + 1]--; if(i < k - 1) e[p] = true; } } } FOR(i, 1, n) f[i] += f[i - 1]; string ans; REP(i, n) { if(e[i] && f[i]) ans += "?"; else if(e[i]) ans += "_"; else ans += "X"; } return ans; }
#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...