답안 #979652

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
979652 2024-05-11T09:27:52 Z vjudge1 벽 칠하기 (APIO20_paint) C++17
28 / 100
952 ms 324180 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];
        }
    }
    for (int i = 0; i < n; i++) {
        if (to[i][0] == i) {
            return -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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 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 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 3 ms 12892 KB Output is correct
14 Correct 3 ms 12888 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 3 ms 12892 KB Output is correct
18 Correct 2 ms 12892 KB Output is correct
19 Correct 4 ms 12632 KB Output is correct
20 Correct 3 ms 12636 KB Output is correct
21 Correct 4 ms 12636 KB Output is correct
22 Correct 13 ms 11744 KB Output is correct
23 Correct 13 ms 11608 KB Output is correct
24 Correct 12 ms 11612 KB Output is correct
25 Correct 111 ms 319284 KB Output is correct
26 Correct 37 ms 319316 KB Output is correct
27 Correct 36 ms 319316 KB Output is correct
28 Correct 38 ms 319316 KB Output is correct
29 Correct 35 ms 319316 KB Output is correct
30 Correct 36 ms 319312 KB Output is correct
31 Correct 592 ms 320064 KB Output is correct
32 Correct 583 ms 320084 KB Output is correct
33 Correct 577 ms 320080 KB Output is correct
34 Correct 584 ms 320404 KB Output is correct
35 Correct 595 ms 320068 KB Output is correct
36 Correct 576 ms 320084 KB Output is correct
37 Correct 952 ms 318544 KB Output is correct
38 Correct 941 ms 318812 KB Output is correct
39 Correct 946 ms 318736 KB Output is correct
40 Runtime error 153 ms 324180 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 4440 KB Output is correct
4 Correct 1 ms 4440 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 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 3 ms 12892 KB Output is correct
14 Correct 3 ms 12888 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 3 ms 12892 KB Output is correct
18 Correct 2 ms 12892 KB Output is correct
19 Correct 4 ms 12632 KB Output is correct
20 Correct 3 ms 12636 KB Output is correct
21 Correct 4 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 1 ms 9052 KB Output is correct
28 Correct 2 ms 9052 KB Output is correct
29 Correct 2 ms 6744 KB Output is correct
30 Correct 2 ms 7260 KB Output is correct
31 Correct 1 ms 10588 KB Output is correct
32 Correct 2 ms 7260 KB Output is correct
33 Correct 2 ms 9564 KB Output is correct
34 Correct 3 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 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 9060 KB Output is correct
42 Correct 2 ms 8640 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 13008 KB Output is correct
46 Correct 2 ms 10952 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 13060 KB Output is correct
51 Correct 3 ms 12892 KB Output is correct
52 Correct 3 ms 12892 KB Output is correct
53 Correct 2 ms 12892 KB Output is correct
54 Correct 3 ms 13064 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 12636 KB Output is correct
59 Correct 2 ms 12892 KB Output is correct
60 Correct 3 ms 12636 KB Output is correct
61 Correct 3 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 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 4440 KB Output is correct
6 Correct 1 ms 4440 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 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 3 ms 12892 KB Output is correct
16 Correct 3 ms 12888 KB Output is correct
17 Correct 3 ms 12892 KB Output is correct
18 Correct 2 ms 12892 KB Output is correct
19 Correct 3 ms 12892 KB Output is correct
20 Correct 2 ms 12892 KB Output is correct
21 Correct 4 ms 12632 KB Output is correct
22 Correct 3 ms 12636 KB Output is correct
23 Correct 4 ms 12636 KB Output is correct
24 Correct 13 ms 11744 KB Output is correct
25 Correct 13 ms 11608 KB Output is correct
26 Correct 12 ms 11612 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 1 ms 9052 KB Output is correct
31 Correct 2 ms 9052 KB Output is correct
32 Correct 2 ms 6744 KB Output is correct
33 Correct 2 ms 7260 KB Output is correct
34 Correct 1 ms 10588 KB Output is correct
35 Correct 2 ms 7260 KB Output is correct
36 Correct 2 ms 9564 KB Output is correct
37 Correct 3 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 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 9060 KB Output is correct
45 Correct 2 ms 8640 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 13008 KB Output is correct
49 Correct 2 ms 10952 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 13060 KB Output is correct
54 Correct 3 ms 12892 KB Output is correct
55 Correct 3 ms 12892 KB Output is correct
56 Correct 2 ms 12892 KB Output is correct
57 Correct 3 ms 13064 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 12636 KB Output is correct
62 Correct 2 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 10840 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 10584 KB Output is correct
70 Correct 5 ms 9820 KB Output is correct
71 Correct 5 ms 9820 KB Output is correct
72 Correct 4 ms 9564 KB Output is correct
73 Correct 2 ms 9308 KB Output is correct
74 Correct 4 ms 9308 KB Output is correct
75 Correct 4 ms 9308 KB Output is correct
76 Correct 10 ms 7768 KB Output is correct
77 Correct 12 ms 10332 KB Output is correct
78 Correct 14 ms 8396 KB Output is correct
79 Correct 3 ms 12892 KB Output is correct
80 Correct 3 ms 12892 KB Output is correct
81 Correct 4 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 13148 KB Output is correct
85 Correct 6 ms 13148 KB Output is correct
86 Correct 6 ms 13148 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 12124 KB Output is correct
91 Correct 17 ms 12124 KB Output is correct
92 Correct 17 ms 12120 KB Output is correct
# 결과 실행 시간 메모리 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 4440 KB Output is correct
6 Correct 1 ms 4440 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 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 3 ms 12892 KB Output is correct
16 Correct 3 ms 12888 KB Output is correct
17 Correct 3 ms 12892 KB Output is correct
18 Correct 2 ms 12892 KB Output is correct
19 Correct 3 ms 12892 KB Output is correct
20 Correct 2 ms 12892 KB Output is correct
21 Correct 4 ms 12632 KB Output is correct
22 Correct 3 ms 12636 KB Output is correct
23 Correct 4 ms 12636 KB Output is correct
24 Correct 13 ms 11744 KB Output is correct
25 Correct 13 ms 11608 KB Output is correct
26 Correct 12 ms 11612 KB Output is correct
27 Correct 111 ms 319284 KB Output is correct
28 Correct 37 ms 319316 KB Output is correct
29 Correct 36 ms 319316 KB Output is correct
30 Correct 38 ms 319316 KB Output is correct
31 Correct 35 ms 319316 KB Output is correct
32 Correct 36 ms 319312 KB Output is correct
33 Correct 592 ms 320064 KB Output is correct
34 Correct 583 ms 320084 KB Output is correct
35 Correct 577 ms 320080 KB Output is correct
36 Correct 584 ms 320404 KB Output is correct
37 Correct 595 ms 320068 KB Output is correct
38 Correct 576 ms 320084 KB Output is correct
39 Correct 952 ms 318544 KB Output is correct
40 Correct 941 ms 318812 KB Output is correct
41 Correct 946 ms 318736 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 1 ms 9052 KB Output is correct
46 Correct 2 ms 9052 KB Output is correct
47 Correct 2 ms 6744 KB Output is correct
48 Correct 2 ms 7260 KB Output is correct
49 Correct 1 ms 10588 KB Output is correct
50 Correct 2 ms 7260 KB Output is correct
51 Correct 2 ms 9564 KB Output is correct
52 Correct 3 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 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 9060 KB Output is correct
60 Correct 2 ms 8640 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 13008 KB Output is correct
64 Correct 2 ms 10952 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 13060 KB Output is correct
69 Correct 3 ms 12892 KB Output is correct
70 Correct 3 ms 12892 KB Output is correct
71 Correct 2 ms 12892 KB Output is correct
72 Correct 3 ms 13064 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 12636 KB Output is correct
77 Correct 2 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 10840 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 10584 KB Output is correct
85 Correct 5 ms 9820 KB Output is correct
86 Correct 5 ms 9820 KB Output is correct
87 Correct 4 ms 9564 KB Output is correct
88 Correct 2 ms 9308 KB Output is correct
89 Correct 4 ms 9308 KB Output is correct
90 Correct 4 ms 9308 KB Output is correct
91 Correct 10 ms 7768 KB Output is correct
92 Correct 12 ms 10332 KB Output is correct
93 Correct 14 ms 8396 KB Output is correct
94 Correct 3 ms 12892 KB Output is correct
95 Correct 3 ms 12892 KB Output is correct
96 Correct 4 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 13148 KB Output is correct
100 Correct 6 ms 13148 KB Output is correct
101 Correct 6 ms 13148 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 12124 KB Output is correct
106 Correct 17 ms 12124 KB Output is correct
107 Correct 17 ms 12120 KB Output is correct
108 Correct 42 ms 317528 KB Output is correct
109 Correct 95 ms 234908 KB Output is correct
110 Correct 71 ms 197016 KB Output is correct
111 Correct 65 ms 184404 KB Output is correct
112 Correct 88 ms 245840 KB Output is correct
113 Correct 72 ms 172520 KB Output is correct
114 Correct 280 ms 179756 KB Output is correct
115 Correct 58 ms 163152 KB Output is correct
116 Correct 406 ms 293236 KB Output is correct
117 Correct 214 ms 175700 KB Output is correct
118 Correct 89 ms 203172 KB Output is correct
119 Correct 447 ms 231692 KB Output is correct
120 Correct 545 ms 190164 KB Output is correct
121 Correct 293 ms 191304 KB Output is correct
122 Correct 241 ms 184680 KB Output is correct
123 Correct 136 ms 186196 KB Output is correct
124 Correct 182 ms 301052 KB Output is correct
125 Correct 130 ms 300836 KB Output is correct
126 Incorrect 47 ms 249168 KB Output isn't correct
127 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 4440 KB Output is correct
6 Correct 1 ms 4440 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 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 3 ms 12892 KB Output is correct
16 Correct 3 ms 12888 KB Output is correct
17 Correct 3 ms 12892 KB Output is correct
18 Correct 2 ms 12892 KB Output is correct
19 Correct 3 ms 12892 KB Output is correct
20 Correct 2 ms 12892 KB Output is correct
21 Correct 4 ms 12632 KB Output is correct
22 Correct 3 ms 12636 KB Output is correct
23 Correct 4 ms 12636 KB Output is correct
24 Correct 13 ms 11744 KB Output is correct
25 Correct 13 ms 11608 KB Output is correct
26 Correct 12 ms 11612 KB Output is correct
27 Correct 111 ms 319284 KB Output is correct
28 Correct 37 ms 319316 KB Output is correct
29 Correct 36 ms 319316 KB Output is correct
30 Correct 38 ms 319316 KB Output is correct
31 Correct 35 ms 319316 KB Output is correct
32 Correct 36 ms 319312 KB Output is correct
33 Correct 592 ms 320064 KB Output is correct
34 Correct 583 ms 320084 KB Output is correct
35 Correct 577 ms 320080 KB Output is correct
36 Correct 584 ms 320404 KB Output is correct
37 Correct 595 ms 320068 KB Output is correct
38 Correct 576 ms 320084 KB Output is correct
39 Correct 952 ms 318544 KB Output is correct
40 Correct 941 ms 318812 KB Output is correct
41 Correct 946 ms 318736 KB Output is correct
42 Runtime error 153 ms 324180 KB Execution killed with signal 11
43 Halted 0 ms 0 KB -