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>
using namespace std;
int minimumInstructions (int N, int M, int K, vector <int> C, vector <int> A, vector <vector<int>> B) {
int P[N], L[N], G[N+M], pos[K];
memset(pos, -1, sizeof(pos));
for (int i = 0; i < M; i ++) {
for (int j = 0; j < A[i]; j ++) {
pos[B[i][j]] = i;
}
}
memset(P, 0, sizeof(P));
int lft = 0;
if (pos[C[0]] == -1) return -1;
for (int y = 1; y < N; y ++) {
if (pos[C[y]] == -1) return -1;
if (pos[C[y]] != (pos[C[y-1]] + 1) % M) {
for (int i = lft; i <= y - M; i ++) {
P[i] = 1;
}
lft = y;
}
}
for (; lft <= N - M; lft ++)
P[lft] = 1;
if (P[0]) L[0] = 0;
else return -1;
for (int i = 1; i < N; i ++) {
if (P[i]) L[i] = i;
else L[i] = L[i-1];
}
memset(G, 0, sizeof(G));
for (int i = N - 1; i >= 0; i --) {
if (i - L[i] >= M) {
return -1;
}
G[i] = 1 + G[L[i] + M];
}
return G[0];
}
/*
void solve () {
int N, M, K;
vector <int> C, A;
vector <vector<int>> B;
cin >> N >> M >> K;
C.resize(N);
A.resize(M);
B.resize(M);
for (int i = 0; i < N; i ++) {
cin >> C[i];
}
for (int i = 0; i < M; i ++) {
cin >> A[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) << endl;
}
int main () {
solve();
return 0;
}
*/
# | 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... |