#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 110000;
vector<int> clr[N], pos[N];
bool can[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 (int j = 0; j < A[i]; j++)
clr[B[i][j]].push_back(i);
for (int i = 0; i < N; i++)
for (int j : clr[C[i]])
pos[(j % M - i % M + M) % M].push_back(i);
for (int i = 0; i < M; i++) {
if (pos[i].empty()) continue;
int beg = pos[i][0];
if (M == 1) can[beg] = true;
for (int j = 1; j < (int) pos[i].size(); j++) {
if (pos[i][j] != pos[i][j - 1] + 1)
beg = pos[i][j];
if (pos[i][j] - M + 1 >= beg)
can[pos[i][j]] = true;
}
}
int mn = N, ans = 0, cur = N - 1;
for (int i = N - 1; i >= 0; i--) {
if (can[i]) mn = i - M;
if (i == cur) {
if (mn >= cur)
return -1;
cur = mn;
ans++;
}
}
return ans;
}
# | 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... |