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;
vector < int > v[100100];
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;
vector < vector < int > > d( N + 1 , vector < int > ( M , 1e9 ) );
for( int i = N - 1; i >= 0; i-- ){
for( auto x : v[C[i]] ){
if( d[i + 1][(x + 1) % M] != 1e9 ){
d[i][x] = d[i + 1][(x + 1) % M];
}else d[i][x] = i;
if( d[i][x] - i + 1 >= M )len.push_back(i);
}
}
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;
while( l < r ){
int m = (l + r) / 2;
if( len[m + 1] > st + 1 )r = m;
else l = m + 1;
}
if( st == N - 1 )break;
if( len[l] > st + 1 || len[l] + M - 1 <= st ){
return -1;
}
st = len[l] + M - 1;
ans += 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... |