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>
#include "paint.h"
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
int minimumInstructions(int n, int m, int k, std::vector<int> C,
std::vector<int> A, std::vector<std::vector<int>> B) {
vector <int> R(n), L(n);
auto match = [&](int i, int j){
return binary_search(all(B[j]), C[i]);
};
for ( int i = 0; i < n; i++ ){
int l = i - 1, j = 0;
while ( j < m && l + 1 < n && match(l + 1, j) ){
l++, j++;
} R[i] = j;
}
for ( int i = n - 1; i >= 0; i-- ){
int l = i + 1, j = 0;
while ( j < m && l - 1 >= 0 && match(l - 1, m - j - 1) ){
l--, j++;
} L[i] = j;
}
vector <int> pf(n + 1);
for ( int i = 0; i < n; i++ ){
int l = i - (i > 0 ? L[i - 1] : 0), r = i - (m - R[i]);
if ( l <= r ){
pf[l]++, pf[r + 1]--;
}
}
for ( int i = 1; i < n; i++ ){
pf[i] += pf[i - 1];
}
set <int> st;
for ( int i = 0; i < n; i++ ){
if ( pf[i] > 0 ){
st.insert(i);
}
}
int x = 0, cnt = 0;
while ( x < n ){
auto it = st.lower_bound(x + 1);
if ( it == st.begin() || *prev(it) + m - 1 < x ){
return -1;
} cnt++;
x = *prev(it) + m;
}
return cnt;
}
# | 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... |