Submission #752740

# Submission time Handle Problem Language Result Execution time Memory
752740 2023-06-03T14:29:48 Z benjaminkleyn Painting Walls (APIO20_paint) C++17
51 / 100
582 ms 524288 KB
	#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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 1 ms 1492 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 2 ms 3412 KB Output is correct
14 Correct 2 ms 3540 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 2 ms 3412 KB Output is correct
17 Correct 2 ms 3540 KB Output is correct
18 Correct 3 ms 3412 KB Output is correct
19 Correct 3 ms 5332 KB Output is correct
20 Correct 3 ms 5332 KB Output is correct
21 Correct 3 ms 5332 KB Output is correct
22 Correct 22 ms 27352 KB Output is correct
23 Correct 21 ms 27348 KB Output is correct
24 Correct 21 ms 27476 KB Output is correct
25 Correct 56 ms 80744 KB Output is correct
26 Correct 52 ms 80632 KB Output is correct
27 Correct 49 ms 80700 KB Output is correct
28 Correct 59 ms 80736 KB Output is correct
29 Correct 70 ms 80668 KB Output is correct
30 Correct 51 ms 80716 KB Output is correct
31 Correct 63 ms 105292 KB Output is correct
32 Correct 61 ms 105336 KB Output is correct
33 Correct 66 ms 105292 KB Output is correct
34 Correct 64 ms 105352 KB Output is correct
35 Correct 63 ms 105372 KB Output is correct
36 Correct 65 ms 105276 KB Output is correct
37 Correct 72 ms 106628 KB Output is correct
38 Correct 72 ms 107364 KB Output is correct
39 Correct 83 ms 107428 KB Output is correct
40 Correct 253 ms 410700 KB Output is correct
41 Correct 158 ms 242808 KB Output is correct
42 Correct 255 ms 445552 KB Output is correct
43 Correct 294 ms 279852 KB Output is correct
44 Correct 167 ms 254284 KB Output is correct
45 Correct 260 ms 451724 KB Output is correct
46 Runtime error 582 ms 524288 KB Execution killed with signal 11
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 1 ms 1492 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 2 ms 3412 KB Output is correct
14 Correct 2 ms 3540 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 2 ms 3412 KB Output is correct
17 Correct 2 ms 3540 KB Output is correct
18 Correct 3 ms 3412 KB Output is correct
19 Correct 3 ms 5332 KB Output is correct
20 Correct 3 ms 5332 KB Output is correct
21 Correct 3 ms 5332 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 980 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 1 ms 852 KB Output is correct
30 Correct 1 ms 1108 KB Output is correct
31 Correct 1 ms 1364 KB Output is correct
32 Correct 1 ms 1236 KB Output is correct
33 Correct 2 ms 2900 KB Output is correct
34 Correct 2 ms 3028 KB Output is correct
35 Correct 2 ms 2132 KB Output is correct
36 Correct 2 ms 2772 KB Output is correct
37 Correct 2 ms 2388 KB Output is correct
38 Correct 2 ms 4436 KB Output is correct
39 Correct 1 ms 1108 KB Output is correct
40 Correct 3 ms 4564 KB Output is correct
41 Correct 1 ms 1108 KB Output is correct
42 Correct 2 ms 4052 KB Output is correct
43 Correct 2 ms 2260 KB Output is correct
44 Correct 1 ms 1492 KB Output is correct
45 Correct 1 ms 1492 KB Output is correct
46 Correct 1 ms 1492 KB Output is correct
47 Correct 1 ms 1492 KB Output is correct
48 Correct 1 ms 1492 KB Output is correct
49 Correct 1 ms 1492 KB Output is correct
50 Correct 2 ms 3412 KB Output is correct
51 Correct 2 ms 3540 KB Output is correct
52 Correct 2 ms 3412 KB Output is correct
53 Correct 2 ms 3540 KB Output is correct
54 Correct 2 ms 3412 KB Output is correct
55 Correct 2 ms 3540 KB Output is correct
56 Correct 3 ms 5332 KB Output is correct
57 Correct 1 ms 1620 KB Output is correct
58 Correct 4 ms 5204 KB Output is correct
59 Correct 1 ms 1620 KB Output is correct
60 Correct 3 ms 5204 KB Output is correct
61 Correct 1 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 1 ms 1492 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 1 ms 1492 KB Output is correct
15 Correct 2 ms 3412 KB Output is correct
16 Correct 2 ms 3540 KB Output is correct
17 Correct 2 ms 3540 KB Output is correct
18 Correct 2 ms 3412 KB Output is correct
19 Correct 2 ms 3540 KB Output is correct
20 Correct 3 ms 3412 KB Output is correct
21 Correct 3 ms 5332 KB Output is correct
22 Correct 3 ms 5332 KB Output is correct
23 Correct 3 ms 5332 KB Output is correct
24 Correct 22 ms 27352 KB Output is correct
25 Correct 21 ms 27348 KB Output is correct
26 Correct 21 ms 27476 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 980 KB Output is correct
31 Correct 1 ms 1108 KB Output is correct
32 Correct 1 ms 852 KB Output is correct
33 Correct 1 ms 1108 KB Output is correct
34 Correct 1 ms 1364 KB Output is correct
35 Correct 1 ms 1236 KB Output is correct
36 Correct 2 ms 2900 KB Output is correct
37 Correct 2 ms 3028 KB Output is correct
38 Correct 2 ms 2132 KB Output is correct
39 Correct 2 ms 2772 KB Output is correct
40 Correct 2 ms 2388 KB Output is correct
41 Correct 2 ms 4436 KB Output is correct
42 Correct 1 ms 1108 KB Output is correct
43 Correct 3 ms 4564 KB Output is correct
44 Correct 1 ms 1108 KB Output is correct
45 Correct 2 ms 4052 KB Output is correct
46 Correct 2 ms 2260 KB Output is correct
47 Correct 1 ms 1492 KB Output is correct
48 Correct 1 ms 1492 KB Output is correct
49 Correct 1 ms 1492 KB Output is correct
50 Correct 1 ms 1492 KB Output is correct
51 Correct 1 ms 1492 KB Output is correct
52 Correct 1 ms 1492 KB Output is correct
53 Correct 2 ms 3412 KB Output is correct
54 Correct 2 ms 3540 KB Output is correct
55 Correct 2 ms 3412 KB Output is correct
56 Correct 2 ms 3540 KB Output is correct
57 Correct 2 ms 3412 KB Output is correct
58 Correct 2 ms 3540 KB Output is correct
59 Correct 3 ms 5332 KB Output is correct
60 Correct 1 ms 1620 KB Output is correct
61 Correct 4 ms 5204 KB Output is correct
62 Correct 1 ms 1620 KB Output is correct
63 Correct 3 ms 5204 KB Output is correct
64 Correct 1 ms 1620 KB Output is correct
65 Correct 1 ms 852 KB Output is correct
66 Correct 1 ms 1492 KB Output is correct
67 Correct 1 ms 1492 KB Output is correct
68 Correct 1 ms 1492 KB Output is correct
69 Correct 1 ms 1364 KB Output is correct
70 Correct 3 ms 3156 KB Output is correct
71 Correct 3 ms 3028 KB Output is correct
72 Correct 5 ms 2900 KB Output is correct
73 Correct 2 ms 2772 KB Output is correct
74 Correct 3 ms 2516 KB Output is correct
75 Correct 2 ms 2516 KB Output is correct
76 Correct 18 ms 19284 KB Output is correct
77 Correct 26 ms 23756 KB Output is correct
78 Correct 23 ms 26428 KB Output is correct
79 Correct 1 ms 1492 KB Output is correct
80 Correct 1 ms 1492 KB Output is correct
81 Correct 2 ms 1492 KB Output is correct
82 Correct 1 ms 1492 KB Output is correct
83 Correct 1 ms 1492 KB Output is correct
84 Correct 4 ms 3540 KB Output is correct
85 Correct 3 ms 3540 KB Output is correct
86 Correct 3 ms 3668 KB Output is correct
87 Correct 3 ms 3536 KB Output is correct
88 Correct 3 ms 3668 KB Output is correct
89 Correct 3 ms 3668 KB Output is correct
90 Correct 26 ms 27816 KB Output is correct
91 Correct 29 ms 27740 KB Output is correct
92 Correct 28 ms 27716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 1 ms 1492 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 1 ms 1492 KB Output is correct
15 Correct 2 ms 3412 KB Output is correct
16 Correct 2 ms 3540 KB Output is correct
17 Correct 2 ms 3540 KB Output is correct
18 Correct 2 ms 3412 KB Output is correct
19 Correct 2 ms 3540 KB Output is correct
20 Correct 3 ms 3412 KB Output is correct
21 Correct 3 ms 5332 KB Output is correct
22 Correct 3 ms 5332 KB Output is correct
23 Correct 3 ms 5332 KB Output is correct
24 Correct 22 ms 27352 KB Output is correct
25 Correct 21 ms 27348 KB Output is correct
26 Correct 21 ms 27476 KB Output is correct
27 Correct 56 ms 80744 KB Output is correct
28 Correct 52 ms 80632 KB Output is correct
29 Correct 49 ms 80700 KB Output is correct
30 Correct 59 ms 80736 KB Output is correct
31 Correct 70 ms 80668 KB Output is correct
32 Correct 51 ms 80716 KB Output is correct
33 Correct 63 ms 105292 KB Output is correct
34 Correct 61 ms 105336 KB Output is correct
35 Correct 66 ms 105292 KB Output is correct
36 Correct 64 ms 105352 KB Output is correct
37 Correct 63 ms 105372 KB Output is correct
38 Correct 65 ms 105276 KB Output is correct
39 Correct 72 ms 106628 KB Output is correct
40 Correct 72 ms 107364 KB Output is correct
41 Correct 83 ms 107428 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 980 KB Output is correct
46 Correct 1 ms 1108 KB Output is correct
47 Correct 1 ms 852 KB Output is correct
48 Correct 1 ms 1108 KB Output is correct
49 Correct 1 ms 1364 KB Output is correct
50 Correct 1 ms 1236 KB Output is correct
51 Correct 2 ms 2900 KB Output is correct
52 Correct 2 ms 3028 KB Output is correct
53 Correct 2 ms 2132 KB Output is correct
54 Correct 2 ms 2772 KB Output is correct
55 Correct 2 ms 2388 KB Output is correct
56 Correct 2 ms 4436 KB Output is correct
57 Correct 1 ms 1108 KB Output is correct
58 Correct 3 ms 4564 KB Output is correct
59 Correct 1 ms 1108 KB Output is correct
60 Correct 2 ms 4052 KB Output is correct
61 Correct 2 ms 2260 KB Output is correct
62 Correct 1 ms 1492 KB Output is correct
63 Correct 1 ms 1492 KB Output is correct
64 Correct 1 ms 1492 KB Output is correct
65 Correct 1 ms 1492 KB Output is correct
66 Correct 1 ms 1492 KB Output is correct
67 Correct 1 ms 1492 KB Output is correct
68 Correct 2 ms 3412 KB Output is correct
69 Correct 2 ms 3540 KB Output is correct
70 Correct 2 ms 3412 KB Output is correct
71 Correct 2 ms 3540 KB Output is correct
72 Correct 2 ms 3412 KB Output is correct
73 Correct 2 ms 3540 KB Output is correct
74 Correct 3 ms 5332 KB Output is correct
75 Correct 1 ms 1620 KB Output is correct
76 Correct 4 ms 5204 KB Output is correct
77 Correct 1 ms 1620 KB Output is correct
78 Correct 3 ms 5204 KB Output is correct
79 Correct 1 ms 1620 KB Output is correct
80 Correct 1 ms 852 KB Output is correct
81 Correct 1 ms 1492 KB Output is correct
82 Correct 1 ms 1492 KB Output is correct
83 Correct 1 ms 1492 KB Output is correct
84 Correct 1 ms 1364 KB Output is correct
85 Correct 3 ms 3156 KB Output is correct
86 Correct 3 ms 3028 KB Output is correct
87 Correct 5 ms 2900 KB Output is correct
88 Correct 2 ms 2772 KB Output is correct
89 Correct 3 ms 2516 KB Output is correct
90 Correct 2 ms 2516 KB Output is correct
91 Correct 18 ms 19284 KB Output is correct
92 Correct 26 ms 23756 KB Output is correct
93 Correct 23 ms 26428 KB Output is correct
94 Correct 1 ms 1492 KB Output is correct
95 Correct 1 ms 1492 KB Output is correct
96 Correct 2 ms 1492 KB Output is correct
97 Correct 1 ms 1492 KB Output is correct
98 Correct 1 ms 1492 KB Output is correct
99 Correct 4 ms 3540 KB Output is correct
100 Correct 3 ms 3540 KB Output is correct
101 Correct 3 ms 3668 KB Output is correct
102 Correct 3 ms 3536 KB Output is correct
103 Correct 3 ms 3668 KB Output is correct
104 Correct 3 ms 3668 KB Output is correct
105 Correct 26 ms 27816 KB Output is correct
106 Correct 29 ms 27740 KB Output is correct
107 Correct 28 ms 27716 KB Output is correct
108 Correct 59 ms 80184 KB Output is correct
109 Correct 44 ms 54988 KB Output is correct
110 Correct 35 ms 46700 KB Output is correct
111 Correct 36 ms 43784 KB Output is correct
112 Correct 44 ms 58432 KB Output is correct
113 Correct 27 ms 41028 KB Output is correct
114 Correct 42 ms 63920 KB Output is correct
115 Correct 42 ms 58052 KB Output is correct
116 Correct 65 ms 97140 KB Output is correct
117 Correct 41 ms 58316 KB Output is correct
118 Correct 47 ms 69172 KB Output is correct
119 Correct 50 ms 77260 KB Output is correct
120 Correct 51 ms 62112 KB Output is correct
121 Correct 34 ms 48068 KB Output is correct
122 Correct 60 ms 59316 KB Output is correct
123 Correct 31 ms 46536 KB Output is correct
124 Correct 75 ms 97100 KB Output is correct
125 Correct 60 ms 80464 KB Output is correct
126 Correct 55 ms 73296 KB Output is correct
127 Correct 62 ms 95308 KB Output is correct
128 Correct 46 ms 69820 KB Output is correct
129 Correct 51 ms 66888 KB Output is correct
130 Correct 60 ms 80748 KB Output is correct
131 Correct 51 ms 80844 KB Output is correct
132 Correct 74 ms 80804 KB Output is correct
133 Correct 56 ms 80888 KB Output is correct
134 Correct 54 ms 80972 KB Output is correct
135 Correct 55 ms 80852 KB Output is correct
136 Correct 74 ms 106568 KB Output is correct
137 Correct 72 ms 106464 KB Output is correct
138 Correct 93 ms 106484 KB Output is correct
139 Correct 87 ms 106464 KB Output is correct
140 Correct 71 ms 106628 KB Output is correct
141 Correct 79 ms 106444 KB Output is correct
142 Correct 89 ms 108108 KB Output is correct
143 Correct 61 ms 86220 KB Output is correct
144 Correct 95 ms 108168 KB Output is correct
145 Correct 59 ms 86160 KB Output is correct
146 Correct 82 ms 108168 KB Output is correct
147 Correct 57 ms 86284 KB Output is correct
148 Correct 74 ms 105876 KB Output is correct
149 Correct 93 ms 105716 KB Output is correct
150 Correct 66 ms 105748 KB Output is correct
151 Correct 71 ms 105636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 1 ms 1492 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 1 ms 1492 KB Output is correct
15 Correct 2 ms 3412 KB Output is correct
16 Correct 2 ms 3540 KB Output is correct
17 Correct 2 ms 3540 KB Output is correct
18 Correct 2 ms 3412 KB Output is correct
19 Correct 2 ms 3540 KB Output is correct
20 Correct 3 ms 3412 KB Output is correct
21 Correct 3 ms 5332 KB Output is correct
22 Correct 3 ms 5332 KB Output is correct
23 Correct 3 ms 5332 KB Output is correct
24 Correct 22 ms 27352 KB Output is correct
25 Correct 21 ms 27348 KB Output is correct
26 Correct 21 ms 27476 KB Output is correct
27 Correct 56 ms 80744 KB Output is correct
28 Correct 52 ms 80632 KB Output is correct
29 Correct 49 ms 80700 KB Output is correct
30 Correct 59 ms 80736 KB Output is correct
31 Correct 70 ms 80668 KB Output is correct
32 Correct 51 ms 80716 KB Output is correct
33 Correct 63 ms 105292 KB Output is correct
34 Correct 61 ms 105336 KB Output is correct
35 Correct 66 ms 105292 KB Output is correct
36 Correct 64 ms 105352 KB Output is correct
37 Correct 63 ms 105372 KB Output is correct
38 Correct 65 ms 105276 KB Output is correct
39 Correct 72 ms 106628 KB Output is correct
40 Correct 72 ms 107364 KB Output is correct
41 Correct 83 ms 107428 KB Output is correct
42 Correct 253 ms 410700 KB Output is correct
43 Correct 158 ms 242808 KB Output is correct
44 Correct 255 ms 445552 KB Output is correct
45 Correct 294 ms 279852 KB Output is correct
46 Correct 167 ms 254284 KB Output is correct
47 Correct 260 ms 451724 KB Output is correct
48 Runtime error 582 ms 524288 KB Execution killed with signal 11
49 Halted 0 ms 0 KB -