Submission #949267

#TimeUsernameProblemLanguageResultExecution timeMemory
949267vjudge1Painting Walls (APIO20_paint)C++17
0 / 100
1 ms436 KiB
#include <bits/stdc++.h> #include "paint.h" using namespace std; #define all(x) x.begin(), x.end() #define ar array #define pb push_back #define ln '\n' //#define int long long using i64 = long long; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } int minimumInstructions(int n, int m, int k, std::vector<int> C, std::vector<int> A, std::vector<std::vector<int>> B) { vector <int> R(n), L(n); auto match = [&](int i, int j, int s, int d){ if ( j - i + 1 > m ){ return false; } for (; i <= j; i++ ){ if ( !binary_search(all(B[s]), C[i]) ){ return false; } s += d; } return true; }; for ( int i = 0; i < n; i++ ){ int l = i - 1, r = n; while ( l + 1 < r ){ int md = (l + r) >> 1; if ( match(i, md, 0, 1) ){ l = md; } else r = md; } R[i] = l - i + 1; } for ( int i = n - 1; i >= 0; i-- ){ int l = 0, r = i + 1; while ( l < r ){ int md = (l + r) >> 1; if ( match(md, i, m - 1, -1) ){ r = md; } else l = md + 1; } L[i] = i - r + 1; } vector <int> pf(n + 1); for ( int i = 0; i < n; i++ ){ int l = i - (i > 0 ? L[i - 1] : 0), r = i - (m - R[i]); if ( l <= r ){ pf[l]++, pf[r + 1]--; } } for ( int i = 1; i < n; i++ ){ pf[i] += pf[i - 1]; } set <int> st; for ( int i = 0; i < n; i++ ){ if ( pf[i] > 0 ){ st.insert(i); } } int x = 0, cnt = 0; while ( x < n ){ auto it = st.lower_bound(x + 1); if ( it == st.begin() || *prev(it) + m - 1 < x ){ return -1; } cnt++; x = *prev(it) + m; } return cnt; }
#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...