Submission #105780

#TimeUsernameProblemLanguageResultExecution timeMemory
105780RezwanArefin01Paint By Numbers (IOI16_paint)C++17
90 / 100
10 ms4816 KiB
#include <bits/stdc++.h> #include "paint.h" using namespace std; const int N = 2e5 + 5; bool f[N][105], g[N][105], can_b[N], can_w[N]; int c[105], black[N], white[N], t[N], n, k; string solve_puzzle(string _s, vector<int> _c) { n = _s.size(), k = _c.size(); copy(_c.begin(), _c.end(), c + 1); string s = "." + _s + "."; for(int i = 1; i <= n; ++i) { black[i] = black[i - 1] + (s[i] == 'X'); white[i] = white[i - 1] + (s[i] == '_'); } white[n + 1] = white[n]; f[0][0] = 1; for(int i = 1; i <= n; ++i) { f[i][0] = black[i] == 0; for(int j = 1; j <= k; ++j) { bool w = f[i - 1][j]; bool b = (i >= c[j]) & (s[i - c[j]] != 'X') & (white[i] == white[i - c[j]]) &(i > c[j] ? f[i - c[j] - 1][j - 1] : (j == 1)); f[i][j] = s[i] == '_' ? w : s[i] == 'X' ? b : (w | b); } } g[n + 1][k + 1] = g[n + 2][k + 1] = 1; for(int i = n; i >= 1; --i) { g[i][k + 1] = black[n] == black[i - 1]; for(int j = k; j >= 1; --j) { bool w = g[i + 1][j]; bool b = (n - i + 1 >= c[j]) & (s[i + c[j]] != 'X') & (white[i - 1] == white[i + c[j] - 1]) & g[i + c[j] + 1][j + 1]; g[i][j] = s[i] == '_' ? w : s[i] == 'X' ? b : (w | b); } } for(int i = 1; i <= n; ++i) { if(s[i] == '_') can_w[i] = 1; else { for(int c = 0; c <= k && !can_w[i]; ++c) { can_w[i] |= f[i - 1][c] && g[i + 1][c + 1]; } } for(int j = 1; j <= k; ++j) { if(i >= c[j] && s[i - c[j]] != 'X' && s[i + 1] != 'X' && white[i] == white[i - c[j]] && (i > c[j] ? f[i - c[j] - 1][j - 1] : (j == 1)) && g[i + 2][j + 1]) { t[i - c[j] + 1]++; t[i + 1]--; } } } for(int i = 1; i <= n; ++i) { t[i] += t[i - 1]; can_b[i] = t[i] > 0; } string ans = ""; for(int i = 1; i <= n; ++i) { if(s[i] != '.') ans += s[i]; else { if(can_w[i] && can_b[i]) ans += '?'; else ans += (can_w[i] ? '_' : '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...