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>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define Submit
#ifdef Submit
#include "paint.h"
#endif // Submit
using namespace __gnu_pbds;
using namespace std;
const int N = 1e5 + 10;
vector <int> p[N];
int last[N];
int len[N], ok[N];
int minimumInstructions(int n, int m, int k, vector <int> C, vector <int> A, vector <vector <int>>B) {
for (int i = 0; i < m; ++i) {
for (auto x: B[i])
p[x].push_back(i);
}
for (int i = n - 1; i >= 0; --i) {
for (auto j: p[C[i]]) {
int r = (j - i) % m;
if (r < 0) r += m;
if (last[r] != i + 1) len[r] = 0;
++len[r], last[r] = i;
if (len[r] >= m) ok[i] = 1;
}
}
int i = 0, cnt = 0;
ok[n] = 1;
if (ok[0] == 0) return -1;
while (i < n) {
int _i = -1;
for (int j = i + 1; j <= i + m; ++j) {
if (ok[j]) _i = j;
}
++cnt;
if (_i == -1) return -1;
i = _i;
}
return cnt;
}
#ifndef Submit
int main() {
int N, M, K;
assert(3 == scanf("%d %d %d", &N, &M, &K));
std::vector<int> C(N);
for (int i = 0; i < N; ++i) {
assert(1 == scanf("%d", &C[i]));
}
std::vector<int> A(M);
std::vector<std::vector<int>> B(M);
for (int i = 0; i < M; ++i) {
assert(1 == scanf("%d", &A[i]));
B[i].resize(A[i]);
for (int j = 0; j < A[i]; ++j) {
assert(1 == scanf("%d", &B[i][j]));
}
}
int minimum_instructions = minimumInstructions(N, M, K, C, A, B);
printf("%d\n", minimum_instructions);
return 0;
}
/*
8 3 5
3 3 1 3 4 4 2 2
3 0 1 2
2 2 3
2 3 4
*/
#endif // Submit
# | 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... |