Submission #291360

#TimeUsernameProblemLanguageResultExecution timeMemory
291360muhammad_hokimiyonPainting Walls (APIO20_paint)C++14
100 / 100
470 ms13816 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 ){ if( len.empty() )len.push_back(i); else if( len.back() != i )len.push_back(i); } } G += 1; for( auto x : v[C[i]] ){ dd[x].fi = d[x]; dd[x].se = G; } } reverse( len.begin() , len.end() ); int ans = 0 , st = -1; for( int i = 0 , l = 0; i < (int)len.size(); i++ ){ if( st == N - 1 )break; while( l + 1 < (int)len.size() && len[l + 1] <= st + 1 )l += 1; st = len[l] + M - 1; t[len[l]] += 1; t[len[l] + M] -= 1; ans += 1; l += 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...