Submission #979712

# Submission time Handle Problem Language Result Execution time Memory
979712 2024-05-11T10:16:44 Z vjudge1 Painting Walls (APIO20_paint) C++17
51 / 100
1205 ms 323032 KB
#include <bits/stdc++.h>
#include "paint.h"

using namespace std;
using ll = long long;

const int N1 = 20200;
const int M1 = 2020;

int n, m;

int g[N1][M1];
int f[N1][M1];

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;
        }
    }
}

const int N = 100100;

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

bool able[N] = {};

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


    if (n < N1 && m < M1) {
        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();
        for (int i = 0; i <= n - m; i++) {
            for (int j = 0; j < m; j++) 
                able[i] |= (f[i][j] >= m);
        }
    } else {
        bool used[K + 1] = {};
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < A[i]; j++) {
                used[B[i][j]] = true;
            }
        }
        int cnt = 0;
        map<int, int> mp;
        for (int i = 0; i < m; i++) {
            mp[C[i]]++;
            cnt += used[i];
        }

        for (int i = 0; i <= n - m; i++) {
            able[i] = ((int)mp.size() == m && cnt == m);
            cnt -= used[C[i]];
            cnt += used[C[(i + m) % n]]; 
            mp[C[i]]--;
            mp[C[(i + m) % n]]++;
            if (!mp[C[i]]) mp.erase(C[i]);
        }
    }
    
    int to[n] = {};
    {
        if (!able[0]) return -1;
        if (m == n)
            return 1;
        
        int nxt = 0, w = 0;
        for (int i = 0; i < n; i++) {
            if (able[i]) 
                nxt = (i + m);
            to[i] = max(nxt, i);
        }
    }

    int res = 1e9;

    int x = 0, ans = 0;
    while (x < n && x != to[x]) {
        ans++;
        x = to[x];
    }
    if (x == n) return ans;
    return -1;
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:90:22: warning: unused variable 'w' [-Wunused-variable]
   90 |         int nxt = 0, w = 0;
      |                      ^
paint.cpp:98:9: warning: unused variable 'res' [-Wunused-variable]
   98 |     int res = 1e9;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 2 ms 11356 KB Output is correct
8 Correct 2 ms 11356 KB Output is correct
9 Correct 2 ms 11356 KB Output is correct
10 Correct 2 ms 11352 KB Output is correct
11 Correct 2 ms 11352 KB Output is correct
12 Correct 2 ms 11356 KB Output is correct
13 Correct 3 ms 11612 KB Output is correct
14 Correct 3 ms 11612 KB Output is correct
15 Correct 2 ms 11612 KB Output is correct
16 Correct 3 ms 11608 KB Output is correct
17 Correct 3 ms 11608 KB Output is correct
18 Correct 3 ms 11612 KB Output is correct
19 Correct 3 ms 12772 KB Output is correct
20 Correct 4 ms 12632 KB Output is correct
21 Correct 3 ms 12636 KB Output is correct
22 Correct 13 ms 12260 KB Output is correct
23 Correct 12 ms 12380 KB Output is correct
24 Correct 13 ms 12332 KB Output is correct
25 Correct 133 ms 319460 KB Output is correct
26 Correct 38 ms 319572 KB Output is correct
27 Correct 37 ms 319568 KB Output is correct
28 Correct 38 ms 319640 KB Output is correct
29 Correct 37 ms 319572 KB Output is correct
30 Correct 40 ms 319652 KB Output is correct
31 Correct 624 ms 320764 KB Output is correct
32 Correct 582 ms 320740 KB Output is correct
33 Correct 587 ms 320640 KB Output is correct
34 Correct 589 ms 320716 KB Output is correct
35 Correct 595 ms 320644 KB Output is correct
36 Correct 578 ms 320632 KB Output is correct
37 Correct 988 ms 321364 KB Output is correct
38 Correct 985 ms 321352 KB Output is correct
39 Correct 994 ms 321400 KB Output is correct
40 Correct 7 ms 1372 KB Output is correct
41 Correct 6 ms 928 KB Output is correct
42 Correct 13 ms 1624 KB Output is correct
43 Correct 9 ms 1116 KB Output is correct
44 Correct 9 ms 1116 KB Output is correct
45 Correct 12 ms 1628 KB Output is correct
46 Incorrect 55 ms 9340 KB Output isn't correct
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 2 ms 11356 KB Output is correct
8 Correct 2 ms 11356 KB Output is correct
9 Correct 2 ms 11356 KB Output is correct
10 Correct 2 ms 11352 KB Output is correct
11 Correct 2 ms 11352 KB Output is correct
12 Correct 2 ms 11356 KB Output is correct
13 Correct 3 ms 11612 KB Output is correct
14 Correct 3 ms 11612 KB Output is correct
15 Correct 2 ms 11612 KB Output is correct
16 Correct 3 ms 11608 KB Output is correct
17 Correct 3 ms 11608 KB Output is correct
18 Correct 3 ms 11612 KB Output is correct
19 Correct 3 ms 12772 KB Output is correct
20 Correct 4 ms 12632 KB Output is correct
21 Correct 3 ms 12636 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 2 ms 7316 KB Output is correct
28 Correct 2 ms 8792 KB Output is correct
29 Correct 1 ms 7260 KB Output is correct
30 Correct 1 ms 8796 KB Output is correct
31 Correct 2 ms 11100 KB Output is correct
32 Correct 2 ms 10844 KB Output is correct
33 Correct 3 ms 11100 KB Output is correct
34 Correct 2 ms 11096 KB Output is correct
35 Correct 2 ms 7512 KB Output is correct
36 Correct 2 ms 10840 KB Output is correct
37 Correct 2 ms 8792 KB Output is correct
38 Correct 1 ms 10588 KB Output is correct
39 Correct 1 ms 8540 KB Output is correct
40 Correct 2 ms 10588 KB Output is correct
41 Correct 2 ms 8540 KB Output is correct
42 Correct 2 ms 12636 KB Output is correct
43 Correct 2 ms 8540 KB Output is correct
44 Correct 2 ms 11356 KB Output is correct
45 Correct 2 ms 11356 KB Output is correct
46 Correct 2 ms 11356 KB Output is correct
47 Correct 2 ms 11356 KB Output is correct
48 Correct 2 ms 11356 KB Output is correct
49 Correct 2 ms 11356 KB Output is correct
50 Correct 3 ms 11864 KB Output is correct
51 Correct 3 ms 11612 KB Output is correct
52 Correct 3 ms 11640 KB Output is correct
53 Correct 3 ms 11612 KB Output is correct
54 Correct 2 ms 11860 KB Output is correct
55 Correct 2 ms 11612 KB Output is correct
56 Correct 3 ms 12636 KB Output is correct
57 Correct 3 ms 11612 KB Output is correct
58 Correct 4 ms 12900 KB Output is correct
59 Correct 3 ms 11612 KB Output is correct
60 Correct 3 ms 12884 KB Output is correct
61 Correct 2 ms 11608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 2 ms 11356 KB Output is correct
10 Correct 2 ms 11356 KB Output is correct
11 Correct 2 ms 11356 KB Output is correct
12 Correct 2 ms 11352 KB Output is correct
13 Correct 2 ms 11352 KB Output is correct
14 Correct 2 ms 11356 KB Output is correct
15 Correct 3 ms 11612 KB Output is correct
16 Correct 3 ms 11612 KB Output is correct
17 Correct 2 ms 11612 KB Output is correct
18 Correct 3 ms 11608 KB Output is correct
19 Correct 3 ms 11608 KB Output is correct
20 Correct 3 ms 11612 KB Output is correct
21 Correct 3 ms 12772 KB Output is correct
22 Correct 4 ms 12632 KB Output is correct
23 Correct 3 ms 12636 KB Output is correct
24 Correct 13 ms 12260 KB Output is correct
25 Correct 12 ms 12380 KB Output is correct
26 Correct 13 ms 12332 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 2 ms 7316 KB Output is correct
31 Correct 2 ms 8792 KB Output is correct
32 Correct 1 ms 7260 KB Output is correct
33 Correct 1 ms 8796 KB Output is correct
34 Correct 2 ms 11100 KB Output is correct
35 Correct 2 ms 10844 KB Output is correct
36 Correct 3 ms 11100 KB Output is correct
37 Correct 2 ms 11096 KB Output is correct
38 Correct 2 ms 7512 KB Output is correct
39 Correct 2 ms 10840 KB Output is correct
40 Correct 2 ms 8792 KB Output is correct
41 Correct 1 ms 10588 KB Output is correct
42 Correct 1 ms 8540 KB Output is correct
43 Correct 2 ms 10588 KB Output is correct
44 Correct 2 ms 8540 KB Output is correct
45 Correct 2 ms 12636 KB Output is correct
46 Correct 2 ms 8540 KB Output is correct
47 Correct 2 ms 11356 KB Output is correct
48 Correct 2 ms 11356 KB Output is correct
49 Correct 2 ms 11356 KB Output is correct
50 Correct 2 ms 11356 KB Output is correct
51 Correct 2 ms 11356 KB Output is correct
52 Correct 2 ms 11356 KB Output is correct
53 Correct 3 ms 11864 KB Output is correct
54 Correct 3 ms 11612 KB Output is correct
55 Correct 3 ms 11640 KB Output is correct
56 Correct 3 ms 11612 KB Output is correct
57 Correct 2 ms 11860 KB Output is correct
58 Correct 2 ms 11612 KB Output is correct
59 Correct 3 ms 12636 KB Output is correct
60 Correct 3 ms 11612 KB Output is correct
61 Correct 4 ms 12900 KB Output is correct
62 Correct 3 ms 11612 KB Output is correct
63 Correct 3 ms 12884 KB Output is correct
64 Correct 2 ms 11608 KB Output is correct
65 Correct 2 ms 7516 KB Output is correct
66 Correct 2 ms 11356 KB Output is correct
67 Correct 2 ms 11356 KB Output is correct
68 Correct 3 ms 11352 KB Output is correct
69 Correct 3 ms 11356 KB Output is correct
70 Correct 4 ms 11356 KB Output is correct
71 Correct 5 ms 11100 KB Output is correct
72 Correct 3 ms 11100 KB Output is correct
73 Correct 3 ms 10844 KB Output is correct
74 Correct 4 ms 8732 KB Output is correct
75 Correct 4 ms 8796 KB Output is correct
76 Correct 11 ms 8540 KB Output is correct
77 Correct 11 ms 9640 KB Output is correct
78 Correct 12 ms 9820 KB Output is correct
79 Correct 3 ms 11500 KB Output is correct
80 Correct 4 ms 11612 KB Output is correct
81 Correct 3 ms 11612 KB Output is correct
82 Correct 4 ms 11612 KB Output is correct
83 Correct 3 ms 11612 KB Output is correct
84 Correct 5 ms 11612 KB Output is correct
85 Correct 6 ms 11612 KB Output is correct
86 Correct 6 ms 11612 KB Output is correct
87 Correct 7 ms 11612 KB Output is correct
88 Correct 5 ms 11612 KB Output is correct
89 Correct 5 ms 11612 KB Output is correct
90 Correct 22 ms 12704 KB Output is correct
91 Correct 18 ms 12640 KB Output is correct
92 Correct 18 ms 13024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 2 ms 11356 KB Output is correct
10 Correct 2 ms 11356 KB Output is correct
11 Correct 2 ms 11356 KB Output is correct
12 Correct 2 ms 11352 KB Output is correct
13 Correct 2 ms 11352 KB Output is correct
14 Correct 2 ms 11356 KB Output is correct
15 Correct 3 ms 11612 KB Output is correct
16 Correct 3 ms 11612 KB Output is correct
17 Correct 2 ms 11612 KB Output is correct
18 Correct 3 ms 11608 KB Output is correct
19 Correct 3 ms 11608 KB Output is correct
20 Correct 3 ms 11612 KB Output is correct
21 Correct 3 ms 12772 KB Output is correct
22 Correct 4 ms 12632 KB Output is correct
23 Correct 3 ms 12636 KB Output is correct
24 Correct 13 ms 12260 KB Output is correct
25 Correct 12 ms 12380 KB Output is correct
26 Correct 13 ms 12332 KB Output is correct
27 Correct 133 ms 319460 KB Output is correct
28 Correct 38 ms 319572 KB Output is correct
29 Correct 37 ms 319568 KB Output is correct
30 Correct 38 ms 319640 KB Output is correct
31 Correct 37 ms 319572 KB Output is correct
32 Correct 40 ms 319652 KB Output is correct
33 Correct 624 ms 320764 KB Output is correct
34 Correct 582 ms 320740 KB Output is correct
35 Correct 587 ms 320640 KB Output is correct
36 Correct 589 ms 320716 KB Output is correct
37 Correct 595 ms 320644 KB Output is correct
38 Correct 578 ms 320632 KB Output is correct
39 Correct 988 ms 321364 KB Output is correct
40 Correct 985 ms 321352 KB Output is correct
41 Correct 994 ms 321400 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2392 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 2 ms 7316 KB Output is correct
46 Correct 2 ms 8792 KB Output is correct
47 Correct 1 ms 7260 KB Output is correct
48 Correct 1 ms 8796 KB Output is correct
49 Correct 2 ms 11100 KB Output is correct
50 Correct 2 ms 10844 KB Output is correct
51 Correct 3 ms 11100 KB Output is correct
52 Correct 2 ms 11096 KB Output is correct
53 Correct 2 ms 7512 KB Output is correct
54 Correct 2 ms 10840 KB Output is correct
55 Correct 2 ms 8792 KB Output is correct
56 Correct 1 ms 10588 KB Output is correct
57 Correct 1 ms 8540 KB Output is correct
58 Correct 2 ms 10588 KB Output is correct
59 Correct 2 ms 8540 KB Output is correct
60 Correct 2 ms 12636 KB Output is correct
61 Correct 2 ms 8540 KB Output is correct
62 Correct 2 ms 11356 KB Output is correct
63 Correct 2 ms 11356 KB Output is correct
64 Correct 2 ms 11356 KB Output is correct
65 Correct 2 ms 11356 KB Output is correct
66 Correct 2 ms 11356 KB Output is correct
67 Correct 2 ms 11356 KB Output is correct
68 Correct 3 ms 11864 KB Output is correct
69 Correct 3 ms 11612 KB Output is correct
70 Correct 3 ms 11640 KB Output is correct
71 Correct 3 ms 11612 KB Output is correct
72 Correct 2 ms 11860 KB Output is correct
73 Correct 2 ms 11612 KB Output is correct
74 Correct 3 ms 12636 KB Output is correct
75 Correct 3 ms 11612 KB Output is correct
76 Correct 4 ms 12900 KB Output is correct
77 Correct 3 ms 11612 KB Output is correct
78 Correct 3 ms 12884 KB Output is correct
79 Correct 2 ms 11608 KB Output is correct
80 Correct 2 ms 7516 KB Output is correct
81 Correct 2 ms 11356 KB Output is correct
82 Correct 2 ms 11356 KB Output is correct
83 Correct 3 ms 11352 KB Output is correct
84 Correct 3 ms 11356 KB Output is correct
85 Correct 4 ms 11356 KB Output is correct
86 Correct 5 ms 11100 KB Output is correct
87 Correct 3 ms 11100 KB Output is correct
88 Correct 3 ms 10844 KB Output is correct
89 Correct 4 ms 8732 KB Output is correct
90 Correct 4 ms 8796 KB Output is correct
91 Correct 11 ms 8540 KB Output is correct
92 Correct 11 ms 9640 KB Output is correct
93 Correct 12 ms 9820 KB Output is correct
94 Correct 3 ms 11500 KB Output is correct
95 Correct 4 ms 11612 KB Output is correct
96 Correct 3 ms 11612 KB Output is correct
97 Correct 4 ms 11612 KB Output is correct
98 Correct 3 ms 11612 KB Output is correct
99 Correct 5 ms 11612 KB Output is correct
100 Correct 6 ms 11612 KB Output is correct
101 Correct 6 ms 11612 KB Output is correct
102 Correct 7 ms 11612 KB Output is correct
103 Correct 5 ms 11612 KB Output is correct
104 Correct 5 ms 11612 KB Output is correct
105 Correct 22 ms 12704 KB Output is correct
106 Correct 18 ms 12640 KB Output is correct
107 Correct 18 ms 13024 KB Output is correct
108 Correct 42 ms 319048 KB Output is correct
109 Correct 98 ms 233556 KB Output is correct
110 Correct 83 ms 199764 KB Output is correct
111 Correct 72 ms 187732 KB Output is correct
112 Correct 95 ms 246912 KB Output is correct
113 Correct 88 ms 175700 KB Output is correct
114 Correct 294 ms 180564 KB Output is correct
115 Correct 66 ms 163652 KB Output is correct
116 Correct 450 ms 291920 KB Output is correct
117 Correct 226 ms 176392 KB Output is correct
118 Correct 84 ms 204568 KB Output is correct
119 Correct 449 ms 230688 KB Output is correct
120 Correct 577 ms 194308 KB Output is correct
121 Correct 305 ms 192176 KB Output is correct
122 Correct 263 ms 185784 KB Output is correct
123 Correct 138 ms 184656 KB Output is correct
124 Correct 197 ms 301096 KB Output is correct
125 Correct 145 ms 299376 KB Output is correct
126 Correct 53 ms 249428 KB Output is correct
127 Correct 289 ms 298884 KB Output is correct
128 Correct 99 ms 217264 KB Output is correct
129 Correct 116 ms 225592 KB Output is correct
130 Correct 39 ms 319572 KB Output is correct
131 Correct 140 ms 320076 KB Output is correct
132 Correct 135 ms 320340 KB Output is correct
133 Correct 129 ms 320796 KB Output is correct
134 Correct 134 ms 320480 KB Output is correct
135 Correct 148 ms 320568 KB Output is correct
136 Correct 894 ms 321772 KB Output is correct
137 Correct 920 ms 321696 KB Output is correct
138 Correct 890 ms 321800 KB Output is correct
139 Correct 885 ms 321764 KB Output is correct
140 Correct 890 ms 321904 KB Output is correct
141 Correct 882 ms 321932 KB Output is correct
142 Correct 1205 ms 322740 KB Output is correct
143 Correct 614 ms 320856 KB Output is correct
144 Correct 1195 ms 323032 KB Output is correct
145 Correct 595 ms 320932 KB Output is correct
146 Correct 1205 ms 322928 KB Output is correct
147 Correct 606 ms 321048 KB Output is correct
148 Correct 709 ms 321264 KB Output is correct
149 Correct 472 ms 321108 KB Output is correct
150 Correct 347 ms 321016 KB Output is correct
151 Correct 294 ms 320420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 2 ms 11356 KB Output is correct
10 Correct 2 ms 11356 KB Output is correct
11 Correct 2 ms 11356 KB Output is correct
12 Correct 2 ms 11352 KB Output is correct
13 Correct 2 ms 11352 KB Output is correct
14 Correct 2 ms 11356 KB Output is correct
15 Correct 3 ms 11612 KB Output is correct
16 Correct 3 ms 11612 KB Output is correct
17 Correct 2 ms 11612 KB Output is correct
18 Correct 3 ms 11608 KB Output is correct
19 Correct 3 ms 11608 KB Output is correct
20 Correct 3 ms 11612 KB Output is correct
21 Correct 3 ms 12772 KB Output is correct
22 Correct 4 ms 12632 KB Output is correct
23 Correct 3 ms 12636 KB Output is correct
24 Correct 13 ms 12260 KB Output is correct
25 Correct 12 ms 12380 KB Output is correct
26 Correct 13 ms 12332 KB Output is correct
27 Correct 133 ms 319460 KB Output is correct
28 Correct 38 ms 319572 KB Output is correct
29 Correct 37 ms 319568 KB Output is correct
30 Correct 38 ms 319640 KB Output is correct
31 Correct 37 ms 319572 KB Output is correct
32 Correct 40 ms 319652 KB Output is correct
33 Correct 624 ms 320764 KB Output is correct
34 Correct 582 ms 320740 KB Output is correct
35 Correct 587 ms 320640 KB Output is correct
36 Correct 589 ms 320716 KB Output is correct
37 Correct 595 ms 320644 KB Output is correct
38 Correct 578 ms 320632 KB Output is correct
39 Correct 988 ms 321364 KB Output is correct
40 Correct 985 ms 321352 KB Output is correct
41 Correct 994 ms 321400 KB Output is correct
42 Correct 7 ms 1372 KB Output is correct
43 Correct 6 ms 928 KB Output is correct
44 Correct 13 ms 1624 KB Output is correct
45 Correct 9 ms 1116 KB Output is correct
46 Correct 9 ms 1116 KB Output is correct
47 Correct 12 ms 1628 KB Output is correct
48 Incorrect 55 ms 9340 KB Output isn't correct
49 Halted 0 ms 0 KB -