Submission #979649

# Submission time Handle Problem Language Result Execution time Memory
979649 2024-05-11T09:24:23 Z vjudge1 Painting Walls (APIO20_paint) C++17
28 / 100
960 ms 324624 KB
#include <bits/stdc++.h>
#include "paint.h"

using namespace std;
using ll = long long;

const int N = 20200;
const int M = 2020;

int n, m;

int g[N][M];
int f[N][M];

void precalc() {
    for (int j = 0; j < m; j++) {
        int x = n - 1, y = j;
        while (g[x][y] && f[n - 1][j] < m) {
            f[n - 1][j]++;
            x = (x + 1) % n;
            y = (y + 1) % m;
        }
    }

    for (int i = n - 2; i >= 0; i--) {
        for (int j = 0; j < m; j++) {
            if (g[i][j]) f[i][j] = 1 + f[i + 1][(j + 1) % m];
            else f[i][j] = 0;
        }
    }
}

int to[N][18];
int dt[N][18];

int minimumInstructions(
    int N, int M, int K, vector<int> C,
    vector<int> A, vector<vector<int>> B) {
    n = N,
    m = M;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int x = lower_bound(B[j].begin(), B[j].end(), C[i]) - B[j].begin();
            g[i][j] = (x != A[j] && B[j][x] == C[i]);

        }
    }

    precalc();
    bool able[n] = {};
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) 
            able[i] |= (f[i][j] >= m);
        // cout << able[i] << ' ';
    }
    // cout << '\n';
    {
        int st = 0;
        while (st < n && !able[st]) st++;
        if (st == n) return -1;
        if (m == n)
            return 1;
        
        int nxt = 0, w = 0;
        for (int i = 0; i < n; i++) {
            if (able[(i + st) % n]) {
                nxt = (i + st + m) % n;
                w = 0;
            } 
            if (w >= m) nxt = (st + i) % n;
            to[(i + st) % n][0] = nxt;
            dt[(i + st) % n][0] = (nxt - st - i + 2 * n) % n;
            w++;
        }
        // for (int i = 0; i < n; i++)
        //     cout << to[(i + st) % n][0] << ' ';
        // cout << '\n';
        // for (int i = 0; i < n; i++)
        //     cout << dt[(i + st) % n][0] << ' ';
        // cout << '\n';
    }
    for (int k = 1; k < 18; k++) {
        for (int i = 0; i < n; i++) {
            to[i][k] = to[to[i][k - 1]][k - 1];
            dt[i][k] = dt[i][k - 1] + dt[to[i][k - 1]][k - 1];
        }
    }

    int res = n + 1;
    for (int i = 0; i < n; i++) {
        int x = i;
        int ans = 0;
        int dist = 0;
        for (int k = 17; k >= 0; k--) {
            if (dist + dt[x][k] < n) {
                ans += (1 << k);
                dist += dt[x][k];
                x = to[x][k];
            }
        }
        res = min(res, ans + 1);
    }
    if (res == n + 1) return -1;
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 2 ms 12892 KB Output is correct
13 Correct 2 ms 12888 KB Output is correct
14 Correct 3 ms 12892 KB Output is correct
15 Correct 2 ms 12892 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 3 ms 12892 KB Output is correct
18 Correct 3 ms 12888 KB Output is correct
19 Correct 3 ms 12636 KB Output is correct
20 Correct 3 ms 12636 KB Output is correct
21 Correct 3 ms 12636 KB Output is correct
22 Correct 12 ms 11744 KB Output is correct
23 Correct 13 ms 12124 KB Output is correct
24 Correct 12 ms 12124 KB Output is correct
25 Correct 151 ms 319316 KB Output is correct
26 Correct 41 ms 319316 KB Output is correct
27 Correct 37 ms 319316 KB Output is correct
28 Correct 36 ms 319312 KB Output is correct
29 Correct 37 ms 319320 KB Output is correct
30 Correct 41 ms 319316 KB Output is correct
31 Correct 583 ms 320392 KB Output is correct
32 Correct 587 ms 320420 KB Output is correct
33 Correct 605 ms 320492 KB Output is correct
34 Correct 581 ms 320340 KB Output is correct
35 Correct 578 ms 320428 KB Output is correct
36 Correct 579 ms 320340 KB Output is correct
37 Correct 953 ms 319216 KB Output is correct
38 Correct 942 ms 319248 KB Output is correct
39 Correct 960 ms 319316 KB Output is correct
40 Runtime error 160 ms 324624 KB Execution killed with signal 11
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 2 ms 12892 KB Output is correct
13 Correct 2 ms 12888 KB Output is correct
14 Correct 3 ms 12892 KB Output is correct
15 Correct 2 ms 12892 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 3 ms 12892 KB Output is correct
18 Correct 3 ms 12888 KB Output is correct
19 Correct 3 ms 12636 KB Output is correct
20 Correct 3 ms 12636 KB Output is correct
21 Correct 3 ms 12636 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 2 ms 9052 KB Output is correct
28 Correct 2 ms 9164 KB Output is correct
29 Correct 2 ms 6848 KB Output is correct
30 Correct 2 ms 7260 KB Output is correct
31 Correct 1 ms 10588 KB Output is correct
32 Correct 1 ms 7364 KB Output is correct
33 Correct 2 ms 9564 KB Output is correct
34 Correct 2 ms 9820 KB Output is correct
35 Correct 2 ms 9052 KB Output is correct
36 Correct 2 ms 9564 KB Output is correct
37 Correct 2 ms 9308 KB Output is correct
38 Correct 2 ms 8540 KB Output is correct
39 Correct 2 ms 9052 KB Output is correct
40 Correct 2 ms 8540 KB Output is correct
41 Correct 2 ms 9308 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 2 ms 9052 KB Output is correct
44 Correct 2 ms 12892 KB Output is correct
45 Correct 2 ms 12892 KB Output is correct
46 Correct 2 ms 10844 KB Output is correct
47 Correct 2 ms 10844 KB Output is correct
48 Correct 2 ms 10844 KB Output is correct
49 Correct 2 ms 10844 KB Output is correct
50 Correct 3 ms 12964 KB Output is correct
51 Correct 3 ms 12892 KB Output is correct
52 Correct 3 ms 12892 KB Output is correct
53 Correct 3 ms 12892 KB Output is correct
54 Correct 3 ms 12892 KB Output is correct
55 Correct 3 ms 12892 KB Output is correct
56 Correct 3 ms 12636 KB Output is correct
57 Correct 3 ms 12892 KB Output is correct
58 Correct 3 ms 12784 KB Output is correct
59 Correct 3 ms 12892 KB Output is correct
60 Correct 3 ms 12636 KB Output is correct
61 Correct 3 ms 12892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 2 ms 12892 KB Output is correct
13 Correct 2 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 2 ms 12888 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 3 ms 12892 KB Output is correct
20 Correct 3 ms 12888 KB Output is correct
21 Correct 3 ms 12636 KB Output is correct
22 Correct 3 ms 12636 KB Output is correct
23 Correct 3 ms 12636 KB Output is correct
24 Correct 12 ms 11744 KB Output is correct
25 Correct 13 ms 12124 KB Output is correct
26 Correct 12 ms 12124 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 2 ms 9052 KB Output is correct
31 Correct 2 ms 9164 KB Output is correct
32 Correct 2 ms 6848 KB Output is correct
33 Correct 2 ms 7260 KB Output is correct
34 Correct 1 ms 10588 KB Output is correct
35 Correct 1 ms 7364 KB Output is correct
36 Correct 2 ms 9564 KB Output is correct
37 Correct 2 ms 9820 KB Output is correct
38 Correct 2 ms 9052 KB Output is correct
39 Correct 2 ms 9564 KB Output is correct
40 Correct 2 ms 9308 KB Output is correct
41 Correct 2 ms 8540 KB Output is correct
42 Correct 2 ms 9052 KB Output is correct
43 Correct 2 ms 8540 KB Output is correct
44 Correct 2 ms 9308 KB Output is correct
45 Correct 2 ms 8540 KB Output is correct
46 Correct 2 ms 9052 KB Output is correct
47 Correct 2 ms 12892 KB Output is correct
48 Correct 2 ms 12892 KB Output is correct
49 Correct 2 ms 10844 KB Output is correct
50 Correct 2 ms 10844 KB Output is correct
51 Correct 2 ms 10844 KB Output is correct
52 Correct 2 ms 10844 KB Output is correct
53 Correct 3 ms 12964 KB Output is correct
54 Correct 3 ms 12892 KB Output is correct
55 Correct 3 ms 12892 KB Output is correct
56 Correct 3 ms 12892 KB Output is correct
57 Correct 3 ms 12892 KB Output is correct
58 Correct 3 ms 12892 KB Output is correct
59 Correct 3 ms 12636 KB Output is correct
60 Correct 3 ms 12892 KB Output is correct
61 Correct 3 ms 12784 KB Output is correct
62 Correct 3 ms 12892 KB Output is correct
63 Correct 3 ms 12636 KB Output is correct
64 Correct 3 ms 12892 KB Output is correct
65 Correct 2 ms 8796 KB Output is correct
66 Correct 2 ms 10844 KB Output is correct
67 Correct 3 ms 12892 KB Output is correct
68 Correct 2 ms 12892 KB Output is correct
69 Correct 2 ms 10588 KB Output is correct
70 Correct 5 ms 9820 KB Output is correct
71 Correct 4 ms 9820 KB Output is correct
72 Correct 4 ms 9564 KB Output is correct
73 Correct 2 ms 9548 KB Output is correct
74 Correct 4 ms 9308 KB Output is correct
75 Correct 4 ms 9472 KB Output is correct
76 Correct 11 ms 8560 KB Output is correct
77 Correct 10 ms 10844 KB Output is correct
78 Correct 12 ms 9036 KB Output is correct
79 Correct 3 ms 13028 KB Output is correct
80 Correct 3 ms 12892 KB Output is correct
81 Correct 4 ms 13076 KB Output is correct
82 Correct 3 ms 12892 KB Output is correct
83 Correct 3 ms 12892 KB Output is correct
84 Correct 6 ms 13148 KB Output is correct
85 Correct 6 ms 13212 KB Output is correct
86 Correct 6 ms 13252 KB Output is correct
87 Correct 5 ms 13148 KB Output is correct
88 Correct 6 ms 13148 KB Output is correct
89 Correct 6 ms 13148 KB Output is correct
90 Correct 17 ms 13012 KB Output is correct
91 Correct 17 ms 13144 KB Output is correct
92 Correct 17 ms 13084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 2 ms 12892 KB Output is correct
13 Correct 2 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 2 ms 12888 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 3 ms 12892 KB Output is correct
20 Correct 3 ms 12888 KB Output is correct
21 Correct 3 ms 12636 KB Output is correct
22 Correct 3 ms 12636 KB Output is correct
23 Correct 3 ms 12636 KB Output is correct
24 Correct 12 ms 11744 KB Output is correct
25 Correct 13 ms 12124 KB Output is correct
26 Correct 12 ms 12124 KB Output is correct
27 Correct 151 ms 319316 KB Output is correct
28 Correct 41 ms 319316 KB Output is correct
29 Correct 37 ms 319316 KB Output is correct
30 Correct 36 ms 319312 KB Output is correct
31 Correct 37 ms 319320 KB Output is correct
32 Correct 41 ms 319316 KB Output is correct
33 Correct 583 ms 320392 KB Output is correct
34 Correct 587 ms 320420 KB Output is correct
35 Correct 605 ms 320492 KB Output is correct
36 Correct 581 ms 320340 KB Output is correct
37 Correct 578 ms 320428 KB Output is correct
38 Correct 579 ms 320340 KB Output is correct
39 Correct 953 ms 319216 KB Output is correct
40 Correct 942 ms 319248 KB Output is correct
41 Correct 960 ms 319316 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 2 ms 9052 KB Output is correct
46 Correct 2 ms 9164 KB Output is correct
47 Correct 2 ms 6848 KB Output is correct
48 Correct 2 ms 7260 KB Output is correct
49 Correct 1 ms 10588 KB Output is correct
50 Correct 1 ms 7364 KB Output is correct
51 Correct 2 ms 9564 KB Output is correct
52 Correct 2 ms 9820 KB Output is correct
53 Correct 2 ms 9052 KB Output is correct
54 Correct 2 ms 9564 KB Output is correct
55 Correct 2 ms 9308 KB Output is correct
56 Correct 2 ms 8540 KB Output is correct
57 Correct 2 ms 9052 KB Output is correct
58 Correct 2 ms 8540 KB Output is correct
59 Correct 2 ms 9308 KB Output is correct
60 Correct 2 ms 8540 KB Output is correct
61 Correct 2 ms 9052 KB Output is correct
62 Correct 2 ms 12892 KB Output is correct
63 Correct 2 ms 12892 KB Output is correct
64 Correct 2 ms 10844 KB Output is correct
65 Correct 2 ms 10844 KB Output is correct
66 Correct 2 ms 10844 KB Output is correct
67 Correct 2 ms 10844 KB Output is correct
68 Correct 3 ms 12964 KB Output is correct
69 Correct 3 ms 12892 KB Output is correct
70 Correct 3 ms 12892 KB Output is correct
71 Correct 3 ms 12892 KB Output is correct
72 Correct 3 ms 12892 KB Output is correct
73 Correct 3 ms 12892 KB Output is correct
74 Correct 3 ms 12636 KB Output is correct
75 Correct 3 ms 12892 KB Output is correct
76 Correct 3 ms 12784 KB Output is correct
77 Correct 3 ms 12892 KB Output is correct
78 Correct 3 ms 12636 KB Output is correct
79 Correct 3 ms 12892 KB Output is correct
80 Correct 2 ms 8796 KB Output is correct
81 Correct 2 ms 10844 KB Output is correct
82 Correct 3 ms 12892 KB Output is correct
83 Correct 2 ms 12892 KB Output is correct
84 Correct 2 ms 10588 KB Output is correct
85 Correct 5 ms 9820 KB Output is correct
86 Correct 4 ms 9820 KB Output is correct
87 Correct 4 ms 9564 KB Output is correct
88 Correct 2 ms 9548 KB Output is correct
89 Correct 4 ms 9308 KB Output is correct
90 Correct 4 ms 9472 KB Output is correct
91 Correct 11 ms 8560 KB Output is correct
92 Correct 10 ms 10844 KB Output is correct
93 Correct 12 ms 9036 KB Output is correct
94 Correct 3 ms 13028 KB Output is correct
95 Correct 3 ms 12892 KB Output is correct
96 Correct 4 ms 13076 KB Output is correct
97 Correct 3 ms 12892 KB Output is correct
98 Correct 3 ms 12892 KB Output is correct
99 Correct 6 ms 13148 KB Output is correct
100 Correct 6 ms 13212 KB Output is correct
101 Correct 6 ms 13252 KB Output is correct
102 Correct 5 ms 13148 KB Output is correct
103 Correct 6 ms 13148 KB Output is correct
104 Correct 6 ms 13148 KB Output is correct
105 Correct 17 ms 13012 KB Output is correct
106 Correct 17 ms 13144 KB Output is correct
107 Correct 17 ms 13084 KB Output is correct
108 Correct 39 ms 317760 KB Output is correct
109 Correct 97 ms 234836 KB Output is correct
110 Correct 71 ms 196692 KB Output is correct
111 Correct 65 ms 184404 KB Output is correct
112 Correct 90 ms 245848 KB Output is correct
113 Correct 70 ms 172632 KB Output is correct
114 Correct 275 ms 179912 KB Output is correct
115 Correct 59 ms 163516 KB Output is correct
116 Correct 386 ms 294036 KB Output is correct
117 Correct 212 ms 175916 KB Output is correct
118 Correct 83 ms 203608 KB Output is correct
119 Correct 442 ms 232020 KB Output is correct
120 Correct 553 ms 190744 KB Output is correct
121 Correct 293 ms 191496 KB Output is correct
122 Correct 245 ms 185324 KB Output is correct
123 Correct 136 ms 186196 KB Output is correct
124 Correct 186 ms 301908 KB Output is correct
125 Correct 130 ms 300940 KB Output is correct
126 Incorrect 48 ms 249356 KB Output isn't correct
127 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 2 ms 12892 KB Output is correct
13 Correct 2 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 2 ms 12888 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 3 ms 12892 KB Output is correct
20 Correct 3 ms 12888 KB Output is correct
21 Correct 3 ms 12636 KB Output is correct
22 Correct 3 ms 12636 KB Output is correct
23 Correct 3 ms 12636 KB Output is correct
24 Correct 12 ms 11744 KB Output is correct
25 Correct 13 ms 12124 KB Output is correct
26 Correct 12 ms 12124 KB Output is correct
27 Correct 151 ms 319316 KB Output is correct
28 Correct 41 ms 319316 KB Output is correct
29 Correct 37 ms 319316 KB Output is correct
30 Correct 36 ms 319312 KB Output is correct
31 Correct 37 ms 319320 KB Output is correct
32 Correct 41 ms 319316 KB Output is correct
33 Correct 583 ms 320392 KB Output is correct
34 Correct 587 ms 320420 KB Output is correct
35 Correct 605 ms 320492 KB Output is correct
36 Correct 581 ms 320340 KB Output is correct
37 Correct 578 ms 320428 KB Output is correct
38 Correct 579 ms 320340 KB Output is correct
39 Correct 953 ms 319216 KB Output is correct
40 Correct 942 ms 319248 KB Output is correct
41 Correct 960 ms 319316 KB Output is correct
42 Runtime error 160 ms 324624 KB Execution killed with signal 11
43 Halted 0 ms 0 KB -