#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m, k;
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]++;
}
}
bool subtask1 = 1;
for (int i = 0; i < k; i++) {
if (f[it] > 1) {
subtask1 = 0;
}
if (f[it] == 0) {
return -1;
}
}
int sol = -1;
if (subtask1) {
vector<int> has(k, -1);
vector<int> need(n, 0);
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 sol = 0, pos = need[0], cur = 1;
for (int i = 1; i < n; i++) {
bool ok = false;
ok |= (need[i] == (pos + 1) % m);
if (!ok) {
if (cur < m) {
return -1;
}
sol += (cur + m - 1) / m;
cur = 0;
}
cur++;
pos = need[i];
}
if (cur < m) {
return -1;
}
sol += (cur + m - 1) / m;
return sol;
}
vector<bool> isok(n * m, 0), ok(n, 0);
vector<int> best(n * m, 0);
vector<bool> act(k, 0);
for (int w = 0; w < m; w++) {
for (auto& col : b[w]) {
act[col] = 1;
}
for (int i = 0; i < n; i++) {
if (act[c[i]]) {
isok[i * m + w] = 1;
}
}
for (auto& col : b[w]) {
act[col] = 0;
}
}
for (int i = n - 1; i >= 0; i--) {
for (int w = 0; w < m; w++) {
if (isok[i * m + w]) {
best[i * m + w] = 1;
if (i + 1 < n) {
best[i * m + w] += best[(i + 1) * m + (w + 1) % m];
}
}
}
}
for (int y = 0; y + m - 1 < n; y++) {
for (int w = 0; w < m; w++) {
if (best[y * m + w] >= m) {
ok[y] = 1;
}
}
}
vector<int> inds;
for (int i = 0; i < n; i++) {
if (ok[i]) {
inds.push_back(i);
}
}
if (inds.empty()) {
return -1;
}
assert((int) inds.size() >= 1);
if (inds[0] != 0 || inds.back() != n - m) {
return -1;
}
int l = 0, cost = 0;
while (1) {
int r = l;
cost++;
while (r + 1 < (int) inds.size() && inds[r + 1] <= inds[l] + m) {
r++;
}
if (r == (int) inds.size() - 1) {
if (l < r) {
cost++;
}
break;
}
if (l == r) {
return -1;
}
l = r;
}
return cost;
}
Compilation message
paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:36:23: error: 'it' was not declared in this scope; did you mean 'i'?
36 | if (f[it] > 1) {
| ^~
| i
paint.cpp:39:23: error: 'it' was not declared in this scope; did you mean 'i'?
39 | if (f[it] == 0) {
| ^~
| i
paint.cpp:44:13: warning: unused variable 'sol' [-Wunused-variable]
44 | int sol = -1;
| ^~~