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;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (a); i > (b); --i)
#define TRAV(a,x) for (auto& a: x)
#define sz(x) int(x.size())
using ll = long long;
using vi = vector<int>;
using pii = pair<int,int>;
#define pb push_back
const int INF = int(1e9);
vector<pii> interval;
int check(int a, vector<int> b){
if (!b.empty()) for (auto i : b) if (a==i) return 1;
return 0;
}
int minimumInstructions(
int N, int M, int K, std::vector<int> C,
std::vector<int> A, std::vector<std::vector<int>> B) {
vi window(M,0);
FOR(m,0,M){
FOR(i,0,M){
window[i] += check(C[(m+i)%M], B[m]);
}
}
// interval
for(auto i : window){
if (i==M) interval.pb({0,M-1});
}
FOR(n,M,N){
FOR(i,0,M){
window[i] += (check(C[n], B[(M+n-i)%M]) - check(C[n-M], B[(M+n-i)%M]));
}
for(auto i : window){
if (i==M) interval.pb({n-M,n});
}
}
if (interval.empty()) return -1;
if (interval[0].first != 0) return -1;
else {
int r = interval[0].second; int ans=1; int b=1;
while(b<sz(interval)){
if ((b+1) < sz(interval) && interval[b+1].first <= r) {
++b;
}
else if (interval[b].first <= (r+1)){
r=interval[b].second; ++ans; ++b;
}
else break;
}
if (r!=(N-1)) return -1;
else 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... |