제출 #291356

#제출 시각아이디문제언어결과실행 시간메모리
291356muhammad_hokimiyon벽 칠하기 (APIO20_paint)C++14
63 / 100
1613 ms266372 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]; 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]] ){ int y = x + 1; if( y >= M )y -= M; if( dd[y].fi != 1e9 && dd[y].se == G ){ d[x] = dd[y].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; t[len[l]] += 1; t[len[l] + M] -= 1; ans += 1; } for( int i = 0; i < N; i++ ){ if( i )t[i] += t[i - 1]; if( t[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...