답안 #367773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
367773 2021-02-18T09:53:17 Z KoD 벽 칠하기 (APIO20_paint) C++17
12 / 100
87 ms 14968 KB
#ifndef LOCAL
#include "paint.h"
#endif

#include <vector>
#include <iostream>

template <class T>
using Vec = std::vector<T>;

int rem_euclid(int x, const int y) {
    x %= y;
    return x < 0 ? x + y : x;
}

int minimumInstructions(int N, int M, int K, Vec<int> C, Vec<int>, Vec<Vec<int>> B) {
    Vec<Vec<int>> store(K);
    for (int i = 0; i < M; ++i) {
        for (const auto c: B[i]) {
            store[c].push_back(i);
        }
    }
    Vec<Vec<int>> appear(M);
    for (int i = 0; i < N; ++i) {
        for (const auto j: store[C[i]]) {
            appear[rem_euclid(j - i, M)].push_back(i);
        }
    }
    Vec<int> max_right(N);
    for (const auto &vec: appear) {
        int last = N + 1;
        int to_right = 0;
        for (int i = (int) vec.size() - 1; i >= 0; --i) {
            const auto k = vec[i];
            if (k + 1 != last) {
                to_right = 0;
            }
            to_right += 1;
            max_right[k] = std::max(max_right[i], to_right);
            last = k;
        }
    }
    Vec<int> paint;
    for (int i = 0; i < N; ++i) {
        if (max_right[i] >= M) {
            paint.push_back(i);
        }
    }
    int ret = 0;
    int right = 0;
    int idx = 0;
    while (right < N) {
        while (idx < (int) paint.size() && paint[idx] <= right) {
            idx += 1;
        }
        if (idx == 0) {
            return -1;
        }
        const auto left = paint[idx - 1];
        if (left + M <= right) {
            return -1;
        }
        ret += 1;
        right = left + M;
    }
    return ret;
}

#ifdef LOCAL

int main() {
    int N, M, K;
    std::cin >> N >> M >> K;
    Vec<int> C(N);
    Vec<int> A(M);
    Vec<Vec<int>> B(M);
    for (auto &x: C) {
        std::cin >> x;
    }
    for (int i = 0; i < M; ++i) {
        std::cin >> A[i];
        B[i].resize(A[i]);
        for (auto &x: B[i]) {
            std::cin >> x;
        }
    }
    std::cout << minimumInstructions(N, M, K, C, A, B) << '\n';
    return 0;
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 3 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 3 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 2 ms 2668 KB Output is correct
18 Correct 2 ms 2668 KB Output is correct
19 Correct 3 ms 2668 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 3 ms 2668 KB Output is correct
22 Correct 28 ms 6636 KB Output is correct
23 Correct 28 ms 6636 KB Output is correct
24 Correct 24 ms 6656 KB Output is correct
25 Correct 3 ms 876 KB Output is correct
26 Correct 3 ms 876 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 3 ms 640 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 3 ms 620 KB Output is correct
31 Correct 12 ms 4076 KB Output is correct
32 Correct 12 ms 4076 KB Output is correct
33 Correct 15 ms 4076 KB Output is correct
34 Correct 12 ms 4076 KB Output is correct
35 Correct 11 ms 4076 KB Output is correct
36 Correct 11 ms 4076 KB Output is correct
37 Correct 31 ms 7168 KB Output is correct
38 Correct 31 ms 7148 KB Output is correct
39 Correct 33 ms 7148 KB Output is correct
40 Correct 14 ms 2532 KB Output is correct
41 Correct 9 ms 1640 KB Output is correct
42 Correct 15 ms 2280 KB Output is correct
43 Correct 10 ms 1512 KB Output is correct
44 Correct 8 ms 1388 KB Output is correct
45 Correct 14 ms 2156 KB Output is correct
46 Correct 57 ms 13924 KB Output is correct
47 Correct 34 ms 8688 KB Output is correct
48 Correct 39 ms 11500 KB Output is correct
49 Correct 61 ms 12140 KB Output is correct
50 Correct 62 ms 11756 KB Output is correct
51 Correct 52 ms 8684 KB Output is correct
52 Correct 15 ms 2788 KB Output is correct
53 Correct 15 ms 2660 KB Output is correct
54 Correct 15 ms 2320 KB Output is correct
55 Correct 17 ms 2156 KB Output is correct
56 Correct 14 ms 2096 KB Output is correct
57 Correct 14 ms 2156 KB Output is correct
58 Correct 64 ms 14820 KB Output is correct
59 Correct 60 ms 14820 KB Output is correct
60 Correct 63 ms 14820 KB Output is correct
61 Correct 62 ms 14968 KB Output is correct
62 Correct 69 ms 14820 KB Output is correct
63 Correct 60 ms 14948 KB Output is correct
64 Correct 85 ms 14460 KB Output is correct
65 Correct 87 ms 14316 KB Output is correct
66 Correct 83 ms 14316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 3 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 3 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 2 ms 2668 KB Output is correct
18 Correct 2 ms 2668 KB Output is correct
19 Correct 3 ms 2668 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 3 ms 2668 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 2 ms 2412 KB Output is correct
34 Correct 2 ms 1900 KB Output is correct
35 Correct 2 ms 1644 KB Output is correct
36 Correct 2 ms 2668 KB Output is correct
37 Correct 2 ms 2156 KB Output is correct
38 Correct 2 ms 2412 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 2 ms 2156 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 2 ms 2668 KB Output is correct
43 Incorrect 2 ms 2540 KB Output isn't correct
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 3 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 3 ms 2668 KB Output is correct
18 Correct 2 ms 2668 KB Output is correct
19 Correct 2 ms 2668 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 3 ms 2668 KB Output is correct
22 Correct 2 ms 2668 KB Output is correct
23 Correct 3 ms 2668 KB Output is correct
24 Correct 28 ms 6636 KB Output is correct
25 Correct 28 ms 6636 KB Output is correct
26 Correct 24 ms 6656 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 2 ms 2412 KB Output is correct
37 Correct 2 ms 1900 KB Output is correct
38 Correct 2 ms 1644 KB Output is correct
39 Correct 2 ms 2668 KB Output is correct
40 Correct 2 ms 2156 KB Output is correct
41 Correct 2 ms 2412 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 2 ms 2156 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 2 ms 2668 KB Output is correct
46 Incorrect 2 ms 2540 KB Output isn't correct
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 3 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 3 ms 2668 KB Output is correct
18 Correct 2 ms 2668 KB Output is correct
19 Correct 2 ms 2668 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 3 ms 2668 KB Output is correct
22 Correct 2 ms 2668 KB Output is correct
23 Correct 3 ms 2668 KB Output is correct
24 Correct 28 ms 6636 KB Output is correct
25 Correct 28 ms 6636 KB Output is correct
26 Correct 24 ms 6656 KB Output is correct
27 Correct 3 ms 876 KB Output is correct
28 Correct 3 ms 876 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 3 ms 640 KB Output is correct
31 Correct 3 ms 748 KB Output is correct
32 Correct 3 ms 620 KB Output is correct
33 Correct 12 ms 4076 KB Output is correct
34 Correct 12 ms 4076 KB Output is correct
35 Correct 15 ms 4076 KB Output is correct
36 Correct 12 ms 4076 KB Output is correct
37 Correct 11 ms 4076 KB Output is correct
38 Correct 11 ms 4076 KB Output is correct
39 Correct 31 ms 7168 KB Output is correct
40 Correct 31 ms 7148 KB Output is correct
41 Correct 33 ms 7148 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 2 ms 2412 KB Output is correct
52 Correct 2 ms 1900 KB Output is correct
53 Correct 2 ms 1644 KB Output is correct
54 Correct 2 ms 2668 KB Output is correct
55 Correct 2 ms 2156 KB Output is correct
56 Correct 2 ms 2412 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 2 ms 2156 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 2 ms 2668 KB Output is correct
61 Incorrect 2 ms 2540 KB Output isn't correct
62 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 3 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 3 ms 2668 KB Output is correct
18 Correct 2 ms 2668 KB Output is correct
19 Correct 2 ms 2668 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 3 ms 2668 KB Output is correct
22 Correct 2 ms 2668 KB Output is correct
23 Correct 3 ms 2668 KB Output is correct
24 Correct 28 ms 6636 KB Output is correct
25 Correct 28 ms 6636 KB Output is correct
26 Correct 24 ms 6656 KB Output is correct
27 Correct 3 ms 876 KB Output is correct
28 Correct 3 ms 876 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 3 ms 640 KB Output is correct
31 Correct 3 ms 748 KB Output is correct
32 Correct 3 ms 620 KB Output is correct
33 Correct 12 ms 4076 KB Output is correct
34 Correct 12 ms 4076 KB Output is correct
35 Correct 15 ms 4076 KB Output is correct
36 Correct 12 ms 4076 KB Output is correct
37 Correct 11 ms 4076 KB Output is correct
38 Correct 11 ms 4076 KB Output is correct
39 Correct 31 ms 7168 KB Output is correct
40 Correct 31 ms 7148 KB Output is correct
41 Correct 33 ms 7148 KB Output is correct
42 Correct 14 ms 2532 KB Output is correct
43 Correct 9 ms 1640 KB Output is correct
44 Correct 15 ms 2280 KB Output is correct
45 Correct 10 ms 1512 KB Output is correct
46 Correct 8 ms 1388 KB Output is correct
47 Correct 14 ms 2156 KB Output is correct
48 Correct 57 ms 13924 KB Output is correct
49 Correct 34 ms 8688 KB Output is correct
50 Correct 39 ms 11500 KB Output is correct
51 Correct 61 ms 12140 KB Output is correct
52 Correct 62 ms 11756 KB Output is correct
53 Correct 52 ms 8684 KB Output is correct
54 Correct 15 ms 2788 KB Output is correct
55 Correct 15 ms 2660 KB Output is correct
56 Correct 15 ms 2320 KB Output is correct
57 Correct 17 ms 2156 KB Output is correct
58 Correct 14 ms 2096 KB Output is correct
59 Correct 14 ms 2156 KB Output is correct
60 Correct 64 ms 14820 KB Output is correct
61 Correct 60 ms 14820 KB Output is correct
62 Correct 63 ms 14820 KB Output is correct
63 Correct 62 ms 14968 KB Output is correct
64 Correct 69 ms 14820 KB Output is correct
65 Correct 60 ms 14948 KB Output is correct
66 Correct 85 ms 14460 KB Output is correct
67 Correct 87 ms 14316 KB Output is correct
68 Correct 83 ms 14316 KB Output is correct
69 Correct 1 ms 364 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 1 ms 364 KB Output is correct
74 Correct 1 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 364 KB Output is correct
78 Correct 2 ms 2412 KB Output is correct
79 Correct 2 ms 1900 KB Output is correct
80 Correct 2 ms 1644 KB Output is correct
81 Correct 2 ms 2668 KB Output is correct
82 Correct 2 ms 2156 KB Output is correct
83 Correct 2 ms 2412 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 2 ms 2156 KB Output is correct
86 Correct 1 ms 364 KB Output is correct
87 Correct 2 ms 2668 KB Output is correct
88 Incorrect 2 ms 2540 KB Output isn't correct
89 Halted 0 ms 0 KB -