# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395826 | khangal | Painting Walls (APIO20_paint) | C++14 | 0 ms | 0 KiB |
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;
typedef int ll;
typedef pair<ll,ll> pl;
#define pb push_back
#define ff first
#define ss second
// typedef tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// template< typename T>
// using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n,m,mid,mn,T,sum,c[1234567],h1,h2,x,y,z,l,r,cnt,cnt1,ans;
vector<ll> vec[1234567];
bool ok[1234567],ok1;
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 u:B[i]) vec[u].pb(i);
}
vector<vector<ll> > mp(M)();
for(int i=0;i<N;i++){
for(auto u:vec[C[i]]){
mp[((u-i)%M+M)%M].pb(i);
}
}
vl v(N);
for(auto u:mp){
ll last = N+1;
ll len =0;
for(int i=u.size()-1;i>=0;i--){
if(u[i]+1!=last)last=0;
last++;
v[u[i]]=max(v[u[i]],len);
last=u[i];
}
}
vl ok;
for(int i=0;i<N;i++)if(v[i]>=M)ok.pb(i);
ll Rpoint=0;
ll id=0;
while(Rpoint<N){
while(id<ok.size()&&ok[id]<=Rpoint){
id++;
}
if(id==0)return -1;
ll Lpoint = ok[id-1];
if(Lpoint + M < Rpoint)return -1;
ans++;
}
return ans;
}