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 <bits/stdc++.h>
using namespace std;
int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b){
vector<int> good;
vector<int> ans(m, 0), cnt(m+1, 0);
vector<vector<int>> belongs(k);
for(int i = 0; i<m; i++)
for(auto col : b[i])
belongs[col].push_back(i);
auto add = [&](int p, int sgn){
int col = c[p];
for(auto x : belongs[col]){
int np = (x+p)%m;
cnt[ans[np]]--;
ans[np] += sgn;
cnt[ans[np]]++;
}
};
for(int i = 0; i<m; i++)
add(i, 1);
if(cnt[m]) good.push_back(0);
for(int i = 1; i<=n-m; i++){
add(i-1, -1), add(i+m-1, 1);
if(cnt[m]) good.push_back(i);
}
if(!good.size() || good.front() != 0 || good.back() != n-m)
return -1;
int pg = 0, res = 0;
for(int i = 1; i<(int)good.size(); i++){
if(good[i]-good[pg] > m) return -1;
if(i == (int)good.size()-1 || good[i+1]-good[pg] > m)
res++, pg = i;
}
return res;
}
# | 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... |