# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
397904 | ZikXewen | 벽 칠하기 (APIO20_paint) | C++17 | 1566 ms | 14244 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
int minimumInstructions( int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
auto md = [=](int u){return ((u % M) + M) % M;};
vector<vector<int>> f(K);
vector<int> mem(M), an;
for(int i = 0; i < M; ++i) for(int j: B[i]) f[j].emplace_back(i);
for(int i = 0, ct = 0, tem; i < N; ++i) {
if(i >= M) for(int j: f[C[i - M]]) if(--mem[md(j - i)] == M - 1) --ct;
for(int j: f[C[i]]) if(++mem[md(j - i)] == M) ++ct;
if(ct) an.emplace_back(i);
}
if(an.empty() or upper_bound(an.begin(), an.end(), M - 1) == an.begin()) return -1;
for(int i = -1, ct = 1, tem;; i = tem, ++ct){
tem = *(upper_bound(an.begin(), an.end(), i + M) - 1);
if(tem == N - 1) return ct;
if(tem == i) return -1;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |