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;
int newest[50001], streak[50001];
vector<int> contractors[100001];
bool ok[100001];
int M;
void update(int t, int x){
x = ((x - t) % M + M) % M;
if(newest[x] + 1 == t){
streak[x]++;
}else{
streak[x] = 1;
}
newest[x] = t;
if(streak[x] >= M){
ok[t] = true;
}
}
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
::M = M;
for(int i = 0; i < M; i++){
for(int j = 0; j < A[i]; j++){
contractors[B[i][j]].push_back(i);
}
}
fill(newest, newest + 50001, -1);
for(int i = 0; i < N; i++){
for(auto j : contractors[C[i]]){
update(i, j);
}
}
int ans = 0, l = 0;
while(l < N){
int r = min(N - 1, l + M - 1);
while(!ok[r] && r >= l) r--;
if(r < l) return -1l;
l = r + 1; 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... |