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 "paint.h"
const int N = 100000;
const int M = 50000;
int u[M], d[M];
std::vector<int> like[N];
int minimumInstructions(int n, int m, int k, std::vector<int> c, std::vector<int> a, std::vector<std::vector<int> > b)
{
for (int i = 0; i < m; ++i) for (int j = 0; j < a[i]; ++j) like[b[i][j]].push_back(i);
int pre = -1, last = -1, amt = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < (int)like[c[i]].size(); ++j) {
int cur = i - like[c[i]][j];
cur = (cur % m + m) % m;
if (u[cur] != i) d[cur] = 0;
++d[cur];
u[cur] = i + 1;
if (d[cur] >= m) {
if (i - m > last) return -1;
if (i - m <= pre) last = i;
else {
pre = last;
last = i;
++amt;
}
}
}
}
if (last < n - 1) return -1;
return amt;
}
# | 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... |