제출 #291352

#제출 시각아이디문제언어결과실행 시간메모리
291352muhammad_hokimiyon벽 칠하기 (APIO20_paint)C++14
63 / 100
1608 ms266664 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; 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; vector < int > d(M , 1e9); vector < pair < int , int > > dd(M , make_pair(1e9 , 0)); int G = 0; for( int i = N - 1; i >= 0; i-- ){ for( auto x : v[C[i]] ){ if( dd[(x + 1) % M].fi != 1e9 && dd[(x + 1) % M].se == G ){ d[x] = dd[(x + 1) % M].fi; }else d[x] = i; if( d[x] - i + 1 >= M )len.push_back(i); } G += 1; for( auto x : v[C[i]] ){ dd[x].fi = d[x]; dd[x].se = G; } } 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 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...