제출 #397796

#제출 시각아이디문제언어결과실행 시간메모리
397796yuto1115벽 칠하기 (APIO20_paint)C++17
63 / 100
1590 ms13012 KiB
#include "paint.h" #include <bits/stdc++.h> #define rep(i, n) for(ll i = 0; i < ll(n); i++) #define rep2(i, s, n) for(ll i = ll(s); i < ll(n); i++) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define pb push_back #define eb emplace_back using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vp = vector<P>; using vvp = vector<vp>; using vb = vector<bool>; using vvb = vector<vb>; template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const int inf = 1001001001; //class RMQ { // int n; // vi val; //public: // RMQ(int _n) { // n = 1; // while (n < _n) n *= 2; // val.assign(n * 2, 0); // } // // void update(int i, int x) { // assert(0 <= i and i < n); // i += n; // val[i] += x; // while (i > 1) { // i /= 2; // val[i] = max(val[i * 2], val[i * 2 + 1]); // } // } // // int fold(int l, int r) { // assert(0 <= l and l <= r and r <= n); // l += n, r += n; // int fl = 0, fr = 0; // while (l < r) { // if (l & 1) fl = max(fl, val[l++]); // if (r & 1) fr = max(val[--r], fr); // l >>= 1, r >>= 1; // } // return max(fl, fr); // } //}; int minimumInstructions(int n, int m, int k, vi c, vi a, vvi b) { vvi f(k); rep(i, m) for (int j : b[i]) f[j].pb(i); vi v(m); int cnt = 0; auto add = [&](int i) { assert(0 <= i and i < n); for (int j : f[c[i]]) { j = ((j - i) % m + m) % m; if (++v[j] == m) cnt++; } }; auto erase = [&](int i) { assert(0 <= i and i < n); for (int j : f[c[i]]) { j = ((j - i) % m + m) % m; if (v[j]-- == m) cnt--; } }; rep(i, m - 1) add(i); vi ok; rep(i, n - m + 1) { add(i + m - 1); if (cnt) ok.pb(i); erase(i); } int now = -1, ans = 0; while (now < n - 1) { auto it = upper_bound(all(ok), now + 1); if (it == ok.begin()) return -1; it--; if (*it + m - 1 <= now) return -1; now = *it + m - 1; ans++; } 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...