#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b) {
vector<int> p[k + 1];
set<int> st[n + 1][12];
for(int i = 0; i < m; ++i) {
for(auto x: b[i]) {
p[x].pb(i);
}
}
for(int i = 0; i < n; ++i) {
for(auto x: p[c[i]]) {
st[i][0].insert(x);
}
}
for(int j = 1; j < K; ++j) {
for(int i = 0; i + (1 << j) <= n; ++i) {
for(auto x: st[i][j - 1]) {
if(st[i + (1 << (j - 1))][j - 1].count((x + (1 << (j - 1))) % m)) {
st[i][j].insert(x);
}
}
}
}
vector<bool> can(n, false);
for(int i = 0; i + m - 1 < n; ++i) {
for(auto x: p[c[i]]) {
int cur = x;
int idx = i;
bool ok = true;
for(int j = K - 1; j >= 0; --j) {
if(m & (1 << j)) {
if(!st[idx][j].count(cur)) {
ok = false;
break;
}
cur = (cur + (1 << j)) % m;
idx += (1 << j);
}
}
if(ok) {
assert(idx == i + m);
can[i] = true;
break;
}
}
}
set<int> good;
forn(i, n) if(can[i]) good.insert(i);
int lst = -1e9, ans = 0;
for(int i = 0; i < n; ++i) {
if(lst + m - 1 >= i) continue;
++ans;
if(can[i]) {
lst = i;
} else {
auto it = good.lower_bound(i);
if(it == good.begin()) return -1;
--it;
if(*it + m - 1 < i) return -1;
lst = *it;
}
}
return ans;
}
/*
void solve() {
int n, m, k; cin >> n >> m >> k;
vector<int> c(n); forn(i, n) cin >> c[i];
vector<int> a(m); forn(i, m) cin >> a[i];
vector<vector<int>> b(m);
for(int i = 0; i < m; ++i) {
b[i].resize(a[i]);
for(int j = 0; j < a[i]; ++j) {
cin >> b[i][j];
}
}
cout << minimumInstructions(n, m, k, c, a, b) << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while(t--) {
solve();
}
}
*/
Compilation message
paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:31:24: error: 'K' was not declared in this scope
31 | for(int j = 1; j < K; ++j) {
| ^
paint.cpp:48:25: error: 'K' was not declared in this scope
48 | for(int j = K - 1; j >= 0; --j) {
| ^