# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
979738 | vjudge1 | Painting Walls (APIO20_paint) | C++17 | 2 ms | 2652 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 <bits/stdc++.h>
#include "paint.h"
using namespace std;
using ll = long long;
const int N1 = 20200;
const int M1 = 2020;
int n, m;
const int N = 100100;
const int K = 100100;
bool able[N] = {};
int to[N] = {};
vector<int> inst[K];
vector<vector<int>> f;
int minimumInstructions(
int N, int M, int K, vector<int> C,
vector<int> A, vector<vector<int>> B) {
n = N,
m = M;
for (int i = 0; i < m; i++) {
for (int x : B[i]) {
inst[x].push_back(i);
}
}
for (int i = 0; i < K; i++)
sort(inst[i].begin(), inst[i].end());
auto get = [&](int i, int j) -> int {
if (i == n) return 0;
int x = lower_bound(inst[C[i]].begin(), inst[C[i]].end(), j)
- inst[C[i]].begin();
if (x != (int)inst[C[i]].size() && inst[C[i]][x] == j)
return f[i][x];
return 0;
};
f.resize(n + 1);
for (int i = n - 1; i >= 0; i--) {
f[i].resize((int)inst[C[i]].size() + 1);
for (int j = 0; j < (int)f[i].size(); j++) {
f[i][j] = 1 + get(i + 1, (inst[C[i]][j] + 1) % m);
}
}
for (int i = 0; i <= n - m; i++) {
for (int c : f[i])
if (c >= m)
able[i] = true;
}
{
if (!able[0]) return -1;
int nxt = 0, w = 0;
for (int i = 0; i < n; i++) {
if (able[i])
nxt = (i + m);
to[i] = max(nxt, i);
}
}
int res = 1e9;
int x = 0, ans = 0;
while (x < n && x != to[x]) {
ans++;
x = to[x];
}
if (x == n) return ans;
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... |