Submission #959316

#TimeUsernameProblemLanguageResultExecution timeMemory
959316steveonalexPaint By Numbers (IOI16_paint)C++17
100 / 100
346 ms11936 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1LL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ll mask){return __builtin_popcountll(mask);} int ctz(ll mask){return __builtin_ctzll(mask);} int logOf(ll mask){return 63 - __builtin_clzll(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); // mt19937_64 rng(69); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){ for(auto item: container) out << item << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } const int N = 2e5 + 69, K = 101; bitset<N> dp[K], f[K]; string solve_puzzle(string s, vector<int> c){ s = "_" + s; int n = s.size(); int k = c.size(); c.insert(c.begin(), 0); s = "0" + s; vector<int> pref(n+1); for(int i= 1; i<=n; ++i) pref[i] = pref[i-1] + (s[i] == '.' || s[i] == 'X'); dp[0][0] = f[0][0] = 1; for(int i= 1; i<=n; ++i) if (s[i] != 'X') dp[0][i] = dp[0][i-1] || dp[0][i]; for(int layer = 1; layer<=k; ++layer){ for(int i = c[layer] + 1; i<=n; ++i){ if (pref[i] - pref[i - c[layer]] == c[layer] && s[i - c[layer]] != 'X' && dp[layer - 1][i - c[layer] - 1]){ dp[layer][i] = f[layer][i] = 1; } } for(int i= 1; i<=n; ++i) if (s[i] != 'X') dp[layer][i] = dp[layer][i-1] || dp[layer][i]; } vector<int> sum[2]; for(auto &i: sum) i.resize(n+2); vector<int> nxt(n+1); for(int i = 1; i<=n; ++i){ nxt[i] = nxt[i-1]; if (s[i] == 'X') nxt[i] = i; } vector<int> mis; mis.push_back(n); for(int layer = k; layer >= 1; --layer){ vector<int> rig(n+1, n + 2); for(int i = n; i>=0; --i){ if (i < n) rig[i] = rig[i+1]; if (f[layer][i]) rig[i] = i; } vector<int> bruh(n+2); for(int i: mis){ int j = nxt[i]; int k = rig[j]; if (k > i) continue; sum[0][k+1]++; sum[0][i+1]--; bruh[k]++; bruh[i+1]--; } for(int i= 1; i<=n+1; ++i) bruh[i] += bruh[i-1]; mis.clear(); for(int i= 1; i<=n; ++i) if (bruh[i] && f[layer][i]){ mis.push_back(i - c[layer] - 1); sum[0][i - c[layer]]++; sum[0][i - c[layer] + 1]--; sum[1][i - c[layer] + 1]++; sum[1][i+1]--; } } sum[0][1]++; sum[0][mis.back()+1]--; for(int j = 0; j<=1; ++j) for(int i = 1; i<=n+1; ++i){ sum[j][i] += sum[j][i-1]; } string ans = ""; for(int i = 2; i<=n; ++i){ if (sum[0][i] && sum[1][i]) ans.push_back('?'); else if (sum[0][i]) ans.push_back('_'); else ans.push_back('X'); } return ans; } // int main(void){ // ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // string s; cin >> s; // int k; cin >> k; // vector<int> c(k); // for(int i = 0; i<k; ++i) cin >> c[i]; // cout << solve_puzzle(s, c) << "\n"; // return 0; // }
#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...