Submission #949374

#TimeUsernameProblemLanguageResultExecution timeMemory
949374vjudge1Painting Walls (APIO20_paint)C++17
0 / 100
1 ms1892 KiB
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #include "paint.h" #define rnd(l, r) uniform_int_distribution<int>(l, r)(rng) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); using namespace std; const int inf = 1e9, N1 = 1e5 + 10, MX = 1e5 + 1; int t[N1 * 4]; void update(int pos, int x, int v = 1,int tl = 0, int tr = MX){ if(tl == tr){ t[v] = x; }else{ int mid = (tl + tr) >> 1; if(pos <= mid) update(pos, x, v * 2, tl, mid); else update(pos, x, v * 2 + 1,mid + 1, tr); t[v] = min(t[v * 2], t[v * 2 + 1]); } } int get(int l, int r, int v = 1, int tl = 0, int tr = MX){ if(tl > r || tr < l) return inf; if(tl >= l && tr <= r){ return t[v]; } int mid = (tl + tr) >> 1; return min(get(l, r, v * 2, tl, mid),get(l, r, v * 2 + 1, mid + 1, tr)); } int minimumInstructions( int N, int M, int K, std::vector<int> C, std::vector<int> A, std::vector<std::vector<int>> B) { unordered_map <int,int> mp[M]; vector <int> ind[K + 1]; for(int i = 0; i < M; i++){ for(auto x : B[i]){ ind[x].push_back(i); mp[i][x] = 1; } } memset(t, 0x3f3f, sizeof(t)); for(int i = 0; i + M - 1 < N; i += M){ for(auto j : ind[C[i]]){ bool flag = 1; for(int l = 0; l < M; l++){ if(!mp[(l + j) % M].count(C[i + l])){ flag = 0; break; } } if(flag){ if(i == 0) update(i + M - 1, 1); else{ int x = get(i - 1, i - 1); update(i + M - 1, x + 1); } i += j; break; } } } int ans = get(N - 1, N - 1); if(ans == inf) return -1; return ans; } /* int main() { int N, M, K; assert(3 == scanf("%d %d %d", &N, &M, &K)); std::vector<int> C(N); for (int i = 0; i < N; ++i) { assert(1 == scanf("%d", &C[i])); } std::vector<int> A(M); std::vector<std::vector<int>> B(M); for (int i = 0; i < M; ++i) { assert(1 == scanf("%d", &A[i])); B[i].resize(A[i]); for (int j = 0; j < A[i]; ++j) { assert(1 == scanf("%d", &B[i][j])); } } int minimum_instructions = minimumInstructions(N, M, K, C, A, B); printf("%d\n", minimum_instructions); return 0; } */
#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...