답안 #979662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
979662 2024-05-11T09:35:56 Z vjudge1 벽 칠하기 (APIO20_paint) C++17
28 / 100
960 ms 324176 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);
    }
    
    {
        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 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 = 1e9;
    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];
            }
        }
        if (dist + dt[x][0] >= n)
            res = min(res, ans + 1);
    }
    if (res == 1e9) return -1;
    return res;
}
# 결과 실행 시간 메모리 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 12872 KB Output is correct
8 Correct 2 ms 12888 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 12892 KB Output is correct
16 Correct 4 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 11608 KB Output is correct
23 Correct 13 ms 11612 KB Output is correct
24 Correct 12 ms 11612 KB Output is correct
25 Correct 114 ms 319312 KB Output is correct
26 Correct 38 ms 319312 KB Output is correct
27 Correct 36 ms 319312 KB Output is correct
28 Correct 40 ms 319312 KB Output is correct
29 Correct 37 ms 319388 KB Output is correct
30 Correct 39 ms 319316 KB Output is correct
31 Correct 599 ms 320044 KB Output is correct
32 Correct 616 ms 320152 KB Output is correct
33 Correct 588 ms 320064 KB Output is correct
34 Correct 604 ms 320060 KB Output is correct
35 Correct 586 ms 320080 KB Output is correct
36 Correct 585 ms 320128 KB Output is correct
37 Correct 951 ms 318540 KB Output is correct
38 Correct 940 ms 318540 KB Output is correct
39 Correct 960 ms 318696 KB Output is correct
40 Runtime error 148 ms 324176 KB Execution killed with signal 11
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 12872 KB Output is correct
8 Correct 2 ms 12888 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 12892 KB Output is correct
16 Correct 4 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 4440 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 9052 KB Output is correct
28 Correct 2 ms 9048 KB Output is correct
29 Correct 1 ms 6748 KB Output is correct
30 Correct 1 ms 7260 KB Output is correct
31 Correct 2 ms 10588 KB Output is correct
32 Correct 2 ms 7260 KB Output is correct
33 Correct 3 ms 9564 KB Output is correct
34 Correct 3 ms 9820 KB Output is correct
35 Correct 2 ms 9048 KB Output is correct
36 Correct 2 ms 9560 KB Output is correct
37 Correct 2 ms 9404 KB Output is correct
38 Correct 1 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 9052 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 2 ms 12892 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 2 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 12636 KB Output is correct
59 Correct 3 ms 13000 KB Output is correct
60 Correct 3 ms 12636 KB Output is correct
61 Correct 2 ms 12996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 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 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 12872 KB Output is correct
10 Correct 2 ms 12888 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 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 4 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 11608 KB Output is correct
25 Correct 13 ms 11612 KB Output is correct
26 Correct 12 ms 11612 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 9052 KB Output is correct
31 Correct 2 ms 9048 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 1 ms 7260 KB Output is correct
34 Correct 2 ms 10588 KB Output is correct
35 Correct 2 ms 7260 KB Output is correct
36 Correct 3 ms 9564 KB Output is correct
37 Correct 3 ms 9820 KB Output is correct
38 Correct 2 ms 9048 KB Output is correct
39 Correct 2 ms 9560 KB Output is correct
40 Correct 2 ms 9404 KB Output is correct
41 Correct 1 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 9052 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 2 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 12892 KB Output is correct
57 Correct 3 ms 12892 KB Output is correct
58 Correct 2 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 12636 KB Output is correct
62 Correct 3 ms 13000 KB Output is correct
63 Correct 3 ms 12636 KB Output is correct
64 Correct 2 ms 12996 KB Output is correct
65 Correct 2 ms 8796 KB Output is correct
66 Correct 2 ms 10844 KB Output is correct
67 Correct 2 ms 12888 KB Output is correct
68 Correct 3 ms 12892 KB Output is correct
69 Correct 2 ms 10588 KB Output is correct
70 Correct 4 ms 9820 KB Output is correct
71 Correct 4 ms 9820 KB Output is correct
72 Correct 3 ms 9564 KB Output is correct
73 Correct 2 ms 9304 KB Output is correct
74 Correct 4 ms 9304 KB Output is correct
75 Correct 4 ms 9304 KB Output is correct
76 Correct 13 ms 7776 KB Output is correct
77 Correct 10 ms 10332 KB Output is correct
78 Correct 12 ms 8536 KB Output is correct
79 Correct 3 ms 13020 KB Output is correct
80 Correct 3 ms 12892 KB Output is correct
81 Correct 3 ms 12892 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 13124 KB Output is correct
85 Correct 5 ms 13128 KB Output is correct
86 Correct 7 ms 13148 KB Output is correct
87 Correct 6 ms 13168 KB Output is correct
88 Correct 6 ms 13144 KB Output is correct
89 Correct 6 ms 13148 KB Output is correct
90 Correct 17 ms 12192 KB Output is correct
91 Correct 22 ms 12084 KB Output is correct
92 Correct 17 ms 12124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 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 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 12872 KB Output is correct
10 Correct 2 ms 12888 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 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 4 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 11608 KB Output is correct
25 Correct 13 ms 11612 KB Output is correct
26 Correct 12 ms 11612 KB Output is correct
27 Correct 114 ms 319312 KB Output is correct
28 Correct 38 ms 319312 KB Output is correct
29 Correct 36 ms 319312 KB Output is correct
30 Correct 40 ms 319312 KB Output is correct
31 Correct 37 ms 319388 KB Output is correct
32 Correct 39 ms 319316 KB Output is correct
33 Correct 599 ms 320044 KB Output is correct
34 Correct 616 ms 320152 KB Output is correct
35 Correct 588 ms 320064 KB Output is correct
36 Correct 604 ms 320060 KB Output is correct
37 Correct 586 ms 320080 KB Output is correct
38 Correct 585 ms 320128 KB Output is correct
39 Correct 951 ms 318540 KB Output is correct
40 Correct 940 ms 318540 KB Output is correct
41 Correct 960 ms 318696 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 9052 KB Output is correct
46 Correct 2 ms 9048 KB Output is correct
47 Correct 1 ms 6748 KB Output is correct
48 Correct 1 ms 7260 KB Output is correct
49 Correct 2 ms 10588 KB Output is correct
50 Correct 2 ms 7260 KB Output is correct
51 Correct 3 ms 9564 KB Output is correct
52 Correct 3 ms 9820 KB Output is correct
53 Correct 2 ms 9048 KB Output is correct
54 Correct 2 ms 9560 KB Output is correct
55 Correct 2 ms 9404 KB Output is correct
56 Correct 1 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 9052 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 2 ms 12892 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 2 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 12636 KB Output is correct
77 Correct 3 ms 13000 KB Output is correct
78 Correct 3 ms 12636 KB Output is correct
79 Correct 2 ms 12996 KB Output is correct
80 Correct 2 ms 8796 KB Output is correct
81 Correct 2 ms 10844 KB Output is correct
82 Correct 2 ms 12888 KB Output is correct
83 Correct 3 ms 12892 KB Output is correct
84 Correct 2 ms 10588 KB Output is correct
85 Correct 4 ms 9820 KB Output is correct
86 Correct 4 ms 9820 KB Output is correct
87 Correct 3 ms 9564 KB Output is correct
88 Correct 2 ms 9304 KB Output is correct
89 Correct 4 ms 9304 KB Output is correct
90 Correct 4 ms 9304 KB Output is correct
91 Correct 13 ms 7776 KB Output is correct
92 Correct 10 ms 10332 KB Output is correct
93 Correct 12 ms 8536 KB Output is correct
94 Correct 3 ms 13020 KB Output is correct
95 Correct 3 ms 12892 KB Output is correct
96 Correct 3 ms 12892 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 13124 KB Output is correct
100 Correct 5 ms 13128 KB Output is correct
101 Correct 7 ms 13148 KB Output is correct
102 Correct 6 ms 13168 KB Output is correct
103 Correct 6 ms 13144 KB Output is correct
104 Correct 6 ms 13148 KB Output is correct
105 Correct 17 ms 12192 KB Output is correct
106 Correct 22 ms 12084 KB Output is correct
107 Correct 17 ms 12124 KB Output is correct
108 Correct 39 ms 317532 KB Output is correct
109 Correct 95 ms 234888 KB Output is correct
110 Correct 72 ms 196436 KB Output is correct
111 Correct 66 ms 184348 KB Output is correct
112 Correct 90 ms 245824 KB Output is correct
113 Correct 73 ms 172548 KB Output is correct
114 Correct 280 ms 179368 KB Output is correct
115 Correct 62 ms 163112 KB Output is correct
116 Correct 391 ms 293204 KB Output is correct
117 Correct 212 ms 175488 KB Output is correct
118 Correct 85 ms 203088 KB Output is correct
119 Correct 444 ms 231812 KB Output is correct
120 Correct 567 ms 190080 KB Output is correct
121 Correct 293 ms 191228 KB Output is correct
122 Correct 243 ms 184780 KB Output is correct
123 Correct 138 ms 186188 KB Output is correct
124 Correct 181 ms 301096 KB Output is correct
125 Correct 134 ms 300628 KB Output is correct
126 Incorrect 48 ms 249176 KB Output isn't correct
127 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 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 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 12872 KB Output is correct
10 Correct 2 ms 12888 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 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 4 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 11608 KB Output is correct
25 Correct 13 ms 11612 KB Output is correct
26 Correct 12 ms 11612 KB Output is correct
27 Correct 114 ms 319312 KB Output is correct
28 Correct 38 ms 319312 KB Output is correct
29 Correct 36 ms 319312 KB Output is correct
30 Correct 40 ms 319312 KB Output is correct
31 Correct 37 ms 319388 KB Output is correct
32 Correct 39 ms 319316 KB Output is correct
33 Correct 599 ms 320044 KB Output is correct
34 Correct 616 ms 320152 KB Output is correct
35 Correct 588 ms 320064 KB Output is correct
36 Correct 604 ms 320060 KB Output is correct
37 Correct 586 ms 320080 KB Output is correct
38 Correct 585 ms 320128 KB Output is correct
39 Correct 951 ms 318540 KB Output is correct
40 Correct 940 ms 318540 KB Output is correct
41 Correct 960 ms 318696 KB Output is correct
42 Runtime error 148 ms 324176 KB Execution killed with signal 11
43 Halted 0 ms 0 KB -