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 <vector>
#include <algorithm>
using namespace std;
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
int minimum_instructions = 0;
vector<vector<int>> like(K);
for(int i = 0; i < M; i++)
for(int j : B[i])
like[j].push_back(i);
for(int i = 0; i < N; i++)
if(like[C[i]].empty())
return -1;
int prev_y = -1, y = 0;
while(1) {
if(y < 0 || y == prev_y)
return -1;
bool flag = false;
int max_len = 0;
for(int x : like[C[y]]) {
bool corr = true;
for(int l = 0; l < M; l++) {
if(find(like[C[y + l]].begin(), like[C[y + l]].end(), (x + l) % M) == like[C[y + l]].end()) {
corr = false;
max_len = max(max_len, l);
break;
}
}
if(corr) {
flag = true;
break;
}
else
continue;
}
if(!flag) {
y -= M - max_len;
continue;
}
minimum_instructions++;
prev_y = y;
y += M;
if(y == N)
break;
else
y = min(y, N - M);
}
return minimum_instructions;
}
# | 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... |