Submission #291342

#TimeUsernameProblemLanguageResultExecution timeMemory
291342muhammad_hokimiyonPainting Walls (APIO20_paint)C++14
0 / 100
2 ms2688 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...