Submission #741428

#TimeUsernameProblemLanguageResultExecution timeMemory
741428penguin133Painting Walls (APIO20_paint)C++17
0 / 100
8 ms9712 KiB
#include <bits/stdc++.h> using namespace std; #include "paint.h" //#define int long long #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); bool ok[200005]; vector <int> brr[200005], grr[200005]; int dp[200005]; int stuf[200005]; int minimumInstructions( int N, int M, int K, std::vector<int> C, std::vector<int> A, std::vector<std::vector<int>> B) { for(int i=0;i<M;i++){ for(auto j : B[i])brr[j].push_back(i); } for(int i=0;i<M;i++)stuf[i] = M; for(int i=0;i<M-1;i++){ for(auto j : brr[C[i]])stuf[(j - i + M) % M]--; } for(int i=M-1;i<N;i++){ for(auto j : brr[C[i]])stuf[(j - i + M) % M]--; int rv = i - (M - 1) - 1; if(rv >= 0){ for(auto j : brr[C[rv]])stuf[(j - rv + M) % M]++; } for(int j=0;j<M;j++)if(stuf[j] == 0)ok[i] = 1; } for(int i = 0; i < M - 1; i++)dp[i] = 2e9; for(int i=M - 1;i<N;i++){ dp[i] = 2e9; //cout << ok[i] << ' '; if(ok[i]){ int tmp= 2e9; if(i == M - 1)tmp = 0; for(int j = i - 1; j >= max(0, i - M); j--)tmp = min(tmp, dp[j]); dp[i] = tmp + 1; } } return (dp[N - 1] == 2e9 ? -1 : dp[N - 1]); }
#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...