Submission #571692

#TimeUsernameProblemLanguageResultExecution timeMemory
571692SlavicGPainting Walls (APIO20_paint)C++17
0 / 100
1 ms300 KiB
#include "bits/stdc++.h" using namespace std; #define ll long long #define forn(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(),v.rend() #define pb push_back #define sz(a) (int)a.size() const int K = 18; int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b) { vector<int> p[k + 1]; set<int> st[2 * n + 5][K]; map<pair<int, int>, bool> mp; for(int i = 0; i < m; ++i) { for(auto x: b[i]) { p[x].pb(i); mp[{i, x}] = 1; } } for(int i = 0; i < n; ++i) { for(auto x: p[c[i]]) { st[i][0].insert(x); } } for(int j = 1; j < K; ++j) { for(int i = 0; i + (1 << j) <= n; ++i) { for(auto x: st[i][j - 1]) { if(st[i + (1 << j)][j - 1].count((x + (1 << j)) % m)) { st[i][j].insert(x); } } } } vector<bool> can(n, false); for(int i = 0; i + m - 1 < n; ++i) { for(int x = 0; x < m; ++x) { int cur = x; int idx = i; bool ok = true; for(int j = K - 1; j >= 0; --j) { if(m & (1 << j)) { if(!st[idx][j].count(cur)) { ok = false; break; } cur = (cur + (1 << j)) % m; idx += (1 << j); assert(idx <= n); } } if(ok) { assert(idx == i + m); can[i] = true; break; } } } /* for(int i = 0; i + m - 1 < n; ++i) { for(int x: p[c[i]]) { bool ok = true; for(int times = 0; times < m && ok; ++times) { if(!mp[{(x + times) % m, c[i + times]}]) ok = false; } if(ok) { can[i] = true; break; } } } */ set<int> good; forn(i, n) if(can[i]) good.insert(i); int lst = -1e9, ans = 0; for(int i = 0; i < n; ++i) { if(lst + m - 1 >= i) continue; ++ans; if(can[i]) { lst = i; } else { auto it = good.lower_bound(i); if(it == good.begin()) return -1; --it; if(*it + m - 1 < i) return -1; lst = *it; } } return ans; } /* void solve() { } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t = 1; //cin >> t; while(t--) { solve(); } } */
#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...