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"
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>
#include <array>
#include <algorithm>
#define ll int
using namespace std;
unordered_map <ll, ll> dp[2];
ll p = -1;
vector <ll> color[100000], V;
bool X[100000];
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) {
color[B[i][j]].push_back(i);
}
}
for (int i=0; i<N; ++i) {
for (auto u : color[C[i]]) {
dp[1][u] = (i ? dp[0][(u+M-1)%M] : 0) + 1;
if (dp[1][u] >= M) X[i-M+1] = 1;
}
swap(dp[0], dp[1]);
dp[1].clear();
}
for (int i=0; i<N; ++i) {
if (X[i]) V.push_back(i);
}
p = 0;
int f = 0;
while (p < N) {
auto it = lower_bound(V.begin(), V.end(), p+1);
if (it == V.begin()) return -1;
it = prev(it);
if (*it+M <= p) return -1;
p = *it+M;
++f;
}
return f;
}
# | 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... |