Submission #752740

#TimeUsernameProblemLanguageResultExecution timeMemory
752740benjaminkleynPainting Walls (APIO20_paint)C++17
51 / 100
582 ms524288 KiB
#include <bits/stdc++.h> #include "paint.h" using namespace std; typedef bitset<2000> mask; mask v[100000]; int lg[100001]; bool query(int l, int r, vector<vector<mask>> &raq) { int t = lg[r - l + 1]; return (raq[t][l] & raq[t][r - (1 << t) + 1]).count() > 0; } int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) { lg[1] = 0; for (int x = 2; x <= N; x++) lg[x] = 1 + lg[x/2]; for (int i = 0; i < M; i++) for (int c : B[i]) v[c][i] = 1; mask ones; for (int i = 0; i < M; i++) ones[i] = 1; vector<vector<mask>> raq(lg[N] + 1, vector<mask>(N)); for (int i = 0; i < N; i++) raq[0][i] = ((v[C[i]] >> (i % M)) | (v[C[i]] << ((10000 * M - i) % M))) & ones; for (int t = 1; (1 << t) <= N; t++) for (int i = 0; i + (1 << t) - 1 < N; i++) raq[t][i] = raq[t-1][i] & raq[t-1][i + (1 << (t-1))]; int ans = 0; for (int i = 0, j; i < N; i = j) { mask cur = raq[0][i]; j = i + 1; for (int t = lg[M]; t >= 0; t--) if (j + (1 << t) - 1 < N && (cur & raq[t][j]).count() > 0) { cur &= raq[t][j]; j += (1 << t); } j = min(j, i + M); if (!query(j-M, j-1, raq)) return -1; ans++; } 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...