Submission #399297

#TimeUsernameProblemLanguageResultExecution timeMemory
399297promaPainting Walls (APIO20_paint)C++17
0 / 100
1 ms292 KiB
#include <bits/stdc++.h> using namespace std; bool bin_search (vector <int> &V, int val) { int l = 0, r = int(V.size()) - 1; while (l <= r) { int m = (l + r) / 2; if (V[m] == val) return true; if (V[m] < val) l = m + 1; else r = m - 1; } return false; } int minimumInstructions (int N, int M, int K, vector <int> C, vector <int> A, vector <vector<int>> B) { int P[K], L[N], G[N+M]; for (int i = 0; i < M; i ++) { sort(B[i].begin(), B[i].end()); } memset(P, 0, sizeof(P)); for (int y = 0; y <= N - M; y ++) { for (int x = 0; x < M; x ++) { if (bin_search(B[x], C[y])) { for (int l = 1; l < M; l ++) { int flag = 0; if (!bin_search(B[(x + l) % M], C[y + l])) { flag = 1; break; } if (!flag) { P[y] = 1; } } } } } for (int i = 0; i < N;) { if (P[i]) { L[i] = i; int j; for (j = i + 1; j < N and !P[j]; j ++) { L[j] = i; } i = j; } else { return -1; } } for (int i = N + M - 1; i >= N; i --) { G[i] = 0; } for (int i = N - 1; i >= 0; i --) { if (i - L[i] >= M) { return -1; } G[i] = 1 + G[L[i] + M]; } return G[0]; } /* void solve () { int N, M, K; vector <int> C, A; vector <vector<int>> B; cin >> N >> M >> K; C.resize(N); A.resize(M); B.resize(M); for (int i = 0; i < N; i ++) { cin >> C[i]; } for (int i = 0; i < M; i ++) { cin >> A[i]; B[i].resize(A[i]); for (int j = 0; j < A[i]; j ++) { cin >> B[i][j]; } } cout << minimumInstructions(N, M, K, C, A, B) << endl; } int main () { solve(); 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...