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>
#define fi first
#define se second
#define ll long long
#define dl double long
using namespace std;
int t[100100];
vector < int > v[100100];
void upd( int x , int val )
{
x += 1;
while( x < 100100 ){
t[x] += val;
x += x & -x;
}
}
int get( int x )
{
int res = 0;
x += 1;
while( x > 0 ){
res += t[x];
x -= x & -x;
}
return res;
}
int minimumInstructions( int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B)
{
for( int i = 0; i < M; i++ ){
for( int j = 0; j < A[i]; j++ ){
int x = B[i][j];
v[x].push_back(i);
}
}
vector < int > len;
map < int , int > d , dd;
for( int i = N - 1; i >= 0; i-- ){
for( auto x : v[C[i]] ){
if( dd.find( (x + 1) % M ) != dd.end() ){
d[x] = dd[(x + 1) % M];
}else d[x] = i;
if( d[x] - i + 1 >= M )len.push_back(i);
}
dd = d;
d.clear();
}
sort( len.begin() , len.end() );
len.erase( unique( len.begin() , len.end() ) , len.end() );
int ans = 0 , st = -1;
for( int i = 0; i < (int)len.size(); i++ ){
int l = 0 , r = (int)len.size() - 1;
if( st == N - 1 )break;
while( l < r ){
int m = (l + r) / 2;
if( len[m + 1] > st + 1 )r = m;
else l = m + 1;
}
st = len[l] + M - 1;
upd( len[l] , 1 );
upd( len[l] + M , -1 );
ans += 1;
}
for( int i = 0; i < N; i++ ){
if( get(i) == 0 ){
return -1;
}
}
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... |