# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
850116 | tvladm2009 | Painting Walls (APIO20_paint) | C++17 | 0 ms | 0 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.
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
vector<int> a, c;
vector<vector<int>> b;
n = N;
m = M;
k = K;
c = C;
a = A;
b = B;
assert((int)c.size() == n);
assert((int)a.size() == m);
assert((int)b.size() == m);
for (int i = 0; i < m; i++) {
assert((int)b[i].size() == a[i]);
}
vector<int> f(n, 0);
for (int i = 0; i < m; i++) {
for (auto& it : b[i]) {
f[it]++;
}
}
vector<int> has(k, -1);
vector<int> need(n, 0);
for (int i = 0; i < n; i++) {
for (int i = 0; i < m; i++) {
for (auto& it : b[i]) {
has[it] = i;
}
}
}
for (int i = 0; i < n; i++) {
if (f[c[i]] == 0) {
return -1;
}
need[i] = has[c[i]];
}
int want = need[0];
int cur = 1;
for (int i = 1; i < n; i++) {
want++;
want %= m;
if (need[i] != want) {
cur++;
want = need[i];
}
}
return sol;
}