제출 #396485

#제출 시각아이디문제언어결과실행 시간메모리
396485Kevin_Zhang_TW벽 칠하기 (APIO20_paint)C++17
28 / 100
1583 ms1536 KiB
#include <bits/stdc++.h> #include "paint.h" using namespace std; using ll = long long; #define pb emplace_back #define AI(i) begin(i), end(i) template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); } template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); } #ifdef KEV #define DE(args...) kout("[ " + string(#args) + " ] = ", args) void kout() { cerr << endl; } template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); } template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; } #else #define DE(...) 0 #define debug(...) 0 #endif const int inf = 1e9 + 7; int minimumInstructions( int N, int M, int K, std::vector<int> C, std::vector<int> A, std::vector<std::vector<int>> B) { for (int i = 0;i < M;++i) sort(AI(B[i])); vector<int> is_ok(N+1); auto bad = [&](int i, int j) { return !binary_search(AI(B[j%M]), C[i]); }; for (int h = 0;h < M;++h) { int cnt = 0; for (int i = 0;i < M;++i) cnt += bad(i, h + i); for (int i = 0;i <= N-M;++i) { is_ok[i] |= cnt == 0; if (i == N-M) break; cnt -= bad(i, h + i); cnt += bad(i + M, h + i + M); } } // good is the max index I can take int res = 0, good = 0, bst = -1; is_ok[N] = true; for (int i = 0;i <= N;++i) { if (!is_ok[i]) continue; while (i > good) { if (bst == -1) return -1; ++res; good = bst + M; bst = -1; } chmax(bst, i); } return res; }
#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...