제출 #399391

#제출 시각아이디문제언어결과실행 시간메모리
399391proma벽 칠하기 (APIO20_paint)C++17
0 / 100
1 ms300 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; } bool check (vector <int> &V, int n, int val) { for (int i = 0; i < n; i ++) if (V[i] == val) return true; return false; } int minimumInstructions (int N, int M, int K, vector <int> C, vector <int> A, vector <vector<int>> B) { int P[N], 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 (!check(B[(x + l) % M], A[(x + l) % M], C[y + l])) { flag = 1; break; } if (!flag) { P[y] = 1; } } } } } if (P[0]) L[0] = 0; else return -1; for (int i = 1; i < N; i ++) { if (P[i]) L[i] = i; else L[i] = L[i-1]; } memset(G, 0, sizeof(G)); 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...