Submission #752739

# Submission time Handle Problem Language Result Execution time Memory
752739 2023-06-03T14:28:28 Z benjaminkleyn Painting Walls (APIO20_paint) C++17
28 / 100
230 ms 524288 KB
	#include <bits/stdc++.h>
#include "paint.h"
using namespace std;
typedef bitset<50000> 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 1 ms 384 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 28 ms 30856 KB Output is correct
8 Correct 23 ms 30968 KB Output is correct
9 Correct 21 ms 30932 KB Output is correct
10 Correct 21 ms 30932 KB Output is correct
11 Correct 22 ms 30960 KB Output is correct
12 Correct 21 ms 30888 KB Output is correct
13 Correct 26 ms 33944 KB Output is correct
14 Correct 24 ms 33852 KB Output is correct
15 Correct 23 ms 33956 KB Output is correct
16 Correct 26 ms 33876 KB Output is correct
17 Correct 24 ms 33968 KB Output is correct
18 Correct 24 ms 33876 KB Output is correct
19 Correct 24 ms 36052 KB Output is correct
20 Correct 24 ms 36052 KB Output is correct
21 Correct 24 ms 36104 KB Output is correct
22 Correct 171 ms 432808 KB Output is correct
23 Correct 169 ms 432968 KB Output is correct
24 Correct 173 ms 432920 KB Output is correct
25 Runtime error 230 ms 524288 KB Execution killed with signal 9
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 28 ms 30856 KB Output is correct
8 Correct 23 ms 30968 KB Output is correct
9 Correct 21 ms 30932 KB Output is correct
10 Correct 21 ms 30932 KB Output is correct
11 Correct 22 ms 30960 KB Output is correct
12 Correct 21 ms 30888 KB Output is correct
13 Correct 26 ms 33944 KB Output is correct
14 Correct 24 ms 33852 KB Output is correct
15 Correct 23 ms 33956 KB Output is correct
16 Correct 26 ms 33876 KB Output is correct
17 Correct 24 ms 33968 KB Output is correct
18 Correct 24 ms 33876 KB Output is correct
19 Correct 24 ms 36052 KB Output is correct
20 Correct 24 ms 36052 KB Output is correct
21 Correct 24 ms 36104 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 13 ms 17460 KB Output is correct
28 Correct 14 ms 20436 KB Output is correct
29 Correct 12 ms 16084 KB Output is correct
30 Correct 16 ms 21432 KB Output is correct
31 Correct 20 ms 27816 KB Output is correct
32 Correct 20 ms 23236 KB Output is correct
33 Correct 24 ms 27952 KB Output is correct
34 Correct 20 ms 29652 KB Output is correct
35 Correct 14 ms 19720 KB Output is correct
36 Correct 17 ms 25684 KB Output is correct
37 Correct 16 ms 22944 KB Output is correct
38 Correct 16 ms 23692 KB Output is correct
39 Correct 14 ms 19796 KB Output is correct
40 Correct 16 ms 24232 KB Output is correct
41 Correct 14 ms 20308 KB Output is correct
42 Correct 20 ms 30164 KB Output is correct
43 Correct 15 ms 21516 KB Output is correct
44 Correct 24 ms 30932 KB Output is correct
45 Correct 22 ms 30868 KB Output is correct
46 Correct 22 ms 30932 KB Output is correct
47 Correct 21 ms 30932 KB Output is correct
48 Correct 21 ms 30892 KB Output is correct
49 Correct 22 ms 30948 KB Output is correct
50 Correct 24 ms 33876 KB Output is correct
51 Correct 24 ms 33876 KB Output is correct
52 Correct 23 ms 33896 KB Output is correct
53 Correct 25 ms 33876 KB Output is correct
54 Correct 27 ms 33876 KB Output is correct
55 Correct 23 ms 33896 KB Output is correct
56 Correct 25 ms 36028 KB Output is correct
57 Correct 23 ms 32212 KB Output is correct
58 Correct 25 ms 35924 KB Output is correct
59 Correct 23 ms 32232 KB Output is correct
60 Correct 24 ms 36048 KB Output is correct
61 Correct 23 ms 32168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 28 ms 30856 KB Output is correct
10 Correct 23 ms 30968 KB Output is correct
11 Correct 21 ms 30932 KB Output is correct
12 Correct 21 ms 30932 KB Output is correct
13 Correct 22 ms 30960 KB Output is correct
14 Correct 21 ms 30888 KB Output is correct
15 Correct 26 ms 33944 KB Output is correct
16 Correct 24 ms 33852 KB Output is correct
17 Correct 23 ms 33956 KB Output is correct
18 Correct 26 ms 33876 KB Output is correct
19 Correct 24 ms 33968 KB Output is correct
20 Correct 24 ms 33876 KB Output is correct
21 Correct 24 ms 36052 KB Output is correct
22 Correct 24 ms 36052 KB Output is correct
23 Correct 24 ms 36104 KB Output is correct
24 Correct 171 ms 432808 KB Output is correct
25 Correct 169 ms 432968 KB Output is correct
26 Correct 173 ms 432920 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 13 ms 17460 KB Output is correct
31 Correct 14 ms 20436 KB Output is correct
32 Correct 12 ms 16084 KB Output is correct
33 Correct 16 ms 21432 KB Output is correct
34 Correct 20 ms 27816 KB Output is correct
35 Correct 20 ms 23236 KB Output is correct
36 Correct 24 ms 27952 KB Output is correct
37 Correct 20 ms 29652 KB Output is correct
38 Correct 14 ms 19720 KB Output is correct
39 Correct 17 ms 25684 KB Output is correct
40 Correct 16 ms 22944 KB Output is correct
41 Correct 16 ms 23692 KB Output is correct
42 Correct 14 ms 19796 KB Output is correct
43 Correct 16 ms 24232 KB Output is correct
44 Correct 14 ms 20308 KB Output is correct
45 Correct 20 ms 30164 KB Output is correct
46 Correct 15 ms 21516 KB Output is correct
47 Correct 24 ms 30932 KB Output is correct
48 Correct 22 ms 30868 KB Output is correct
49 Correct 22 ms 30932 KB Output is correct
50 Correct 21 ms 30932 KB Output is correct
51 Correct 21 ms 30892 KB Output is correct
52 Correct 22 ms 30948 KB Output is correct
53 Correct 24 ms 33876 KB Output is correct
54 Correct 24 ms 33876 KB Output is correct
55 Correct 23 ms 33896 KB Output is correct
56 Correct 25 ms 33876 KB Output is correct
57 Correct 27 ms 33876 KB Output is correct
58 Correct 23 ms 33896 KB Output is correct
59 Correct 25 ms 36028 KB Output is correct
60 Correct 23 ms 32212 KB Output is correct
61 Correct 25 ms 35924 KB Output is correct
62 Correct 23 ms 32232 KB Output is correct
63 Correct 24 ms 36048 KB Output is correct
64 Correct 23 ms 32168 KB Output is correct
65 Correct 10 ms 14292 KB Output is correct
66 Correct 21 ms 29524 KB Output is correct
67 Correct 21 ms 30188 KB Output is correct
68 Correct 22 ms 30804 KB Output is correct
69 Correct 20 ms 27860 KB Output is correct
70 Correct 22 ms 29396 KB Output is correct
71 Correct 21 ms 28500 KB Output is correct
72 Correct 20 ms 26452 KB Output is correct
73 Correct 19 ms 26008 KB Output is correct
74 Correct 17 ms 23136 KB Output is correct
75 Correct 18 ms 23252 KB Output is correct
76 Correct 111 ms 242760 KB Output is correct
77 Correct 119 ms 293580 KB Output is correct
78 Correct 134 ms 323808 KB Output is correct
79 Correct 21 ms 30932 KB Output is correct
80 Correct 22 ms 30932 KB Output is correct
81 Correct 23 ms 31060 KB Output is correct
82 Correct 22 ms 30932 KB Output is correct
83 Correct 23 ms 31000 KB Output is correct
84 Correct 27 ms 33928 KB Output is correct
85 Correct 24 ms 34044 KB Output is correct
86 Correct 24 ms 34004 KB Output is correct
87 Correct 25 ms 34004 KB Output is correct
88 Correct 25 ms 34004 KB Output is correct
89 Correct 24 ms 33996 KB Output is correct
90 Correct 150 ms 349936 KB Output is correct
91 Correct 146 ms 349272 KB Output is correct
92 Correct 147 ms 350644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 28 ms 30856 KB Output is correct
10 Correct 23 ms 30968 KB Output is correct
11 Correct 21 ms 30932 KB Output is correct
12 Correct 21 ms 30932 KB Output is correct
13 Correct 22 ms 30960 KB Output is correct
14 Correct 21 ms 30888 KB Output is correct
15 Correct 26 ms 33944 KB Output is correct
16 Correct 24 ms 33852 KB Output is correct
17 Correct 23 ms 33956 KB Output is correct
18 Correct 26 ms 33876 KB Output is correct
19 Correct 24 ms 33968 KB Output is correct
20 Correct 24 ms 33876 KB Output is correct
21 Correct 24 ms 36052 KB Output is correct
22 Correct 24 ms 36052 KB Output is correct
23 Correct 24 ms 36104 KB Output is correct
24 Correct 171 ms 432808 KB Output is correct
25 Correct 169 ms 432968 KB Output is correct
26 Correct 173 ms 432920 KB Output is correct
27 Runtime error 230 ms 524288 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 28 ms 30856 KB Output is correct
10 Correct 23 ms 30968 KB Output is correct
11 Correct 21 ms 30932 KB Output is correct
12 Correct 21 ms 30932 KB Output is correct
13 Correct 22 ms 30960 KB Output is correct
14 Correct 21 ms 30888 KB Output is correct
15 Correct 26 ms 33944 KB Output is correct
16 Correct 24 ms 33852 KB Output is correct
17 Correct 23 ms 33956 KB Output is correct
18 Correct 26 ms 33876 KB Output is correct
19 Correct 24 ms 33968 KB Output is correct
20 Correct 24 ms 33876 KB Output is correct
21 Correct 24 ms 36052 KB Output is correct
22 Correct 24 ms 36052 KB Output is correct
23 Correct 24 ms 36104 KB Output is correct
24 Correct 171 ms 432808 KB Output is correct
25 Correct 169 ms 432968 KB Output is correct
26 Correct 173 ms 432920 KB Output is correct
27 Runtime error 230 ms 524288 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -