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 <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
vector<int> pos[maxn];
vector<int> good[maxn];
int t[maxn], dp[maxn];
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(auto v: B[i])pos[v].push_back(i);
}
for(int i = 0; i < N; i++){
for(auto v: pos[C[i]])good[((v - i)%M + M)%M].push_back(i);
}
for(int i = 0; i < M; i++){
int crr = 0, prv = -1;
for(auto v: good[i]){
if(v == prv + 1)crr++;
else crr = 1;
prv = v;
if(crr >= M)t[v] = 1;
}
}
int prv = -1, last = -1, ans = 0;
for(int i = 0; i < N; i++){
if(t[i])last = i;
if(i - M == prv || i == N-1){
if(last <= prv)return -1;
prv = last;
ans++;
}
}
if(prv < N-1)return -1;
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... |