답안 #685349

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685349 2023-01-24T06:18:12 Z Nursik 벽 칠하기 (APIO20_paint) C++17
28 / 100
1500 ms 33148 KB
#include "paint.h"

#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <cmath>

using namespace std;

#define pb push_back
#define f first
#define s second
#define ll long long

const int maxn = 1e6 + 200, maxm = 1e3 + 200, inf = 1e9;

int n, m, k;
int is[maxn], dp[maxn], t[maxn * 4];
void upd(int pos, int val, int v = 1, int tl = 0, int tr = n - 1){
    if (tl == tr){
        t[v] = val;
        return;
    }
    int tm = (tl + tr) / 2;
    if (pos <= tm)
        upd(pos, val, v + v, tl, tm);
    else
        upd(pos, val, v + v + 1, tm + 1, tr);
    t[v] = min(t[v + v], t[v + v + 1]);
}
int get(int l, int r, int v = 1, int tl = 0, int tr = n - 1){
    if (l <= tl && tr <= r){
        return t[v];
    }
    if (l > tr || r < tl)
        return inf;
    int tm = (tl + tr) / 2;
    return min(get(l, r, v + v, tl, tm), get(l, r, v + v + 1, tm + 1, tr));
}
vector<int> g[maxn];
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
    n = N, m = M, k = K;
    for (int i = 0; i < m; ++i){
        for (auto it : B[i]){
            g[it].pb(i);
        }
    }
    for (int i = m - 1; i < n; ++i){
        for (auto it : g[C[i]]){
            int x = it;
            int ok = 1;
            int z = 0;
           /* if (i == n - 1){
                cout << x << '\n';
            }*/
            while (z < m){
                int ok2 = 0;
                for (auto it2 : B[x]){
                    if (C[i - z] == it2){
                        ok2 = 1;
                        break;
                    }
                }
                if (ok2 == 0){
                    ok = 0;
                    break;
                }
                x = (x - 1 + m) % m;
                z += 1;
            }
            if (ok == 1){
                is[i] = 1;
                break;
            }
        }
    }
    for (int i = 0; i < n; ++i){
        dp[i] = inf;
        upd(i, dp[i]);
    }
    if (is[m - 1] > 0){
        dp[m - 1] = 1;
        upd(m - 1, 1);
    }
    for (int i = m; i < n; ++i){
        if (is[i] > 0){
            dp[i] = min(dp[i], get(i - m, i - 1) + 1);
        }
        upd(i, dp[i]);
    }
    if (dp[n - 1] == inf){
        dp[n - 1] = -1;
    }
    return dp[n - 1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23700 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 11 ms 23812 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 12 ms 23708 KB Output is correct
7 Correct 11 ms 23744 KB Output is correct
8 Correct 11 ms 23716 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 11 ms 23764 KB Output is correct
11 Correct 11 ms 23764 KB Output is correct
12 Correct 11 ms 23764 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 11 ms 23764 KB Output is correct
15 Correct 12 ms 23784 KB Output is correct
16 Correct 13 ms 23888 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 12 ms 23764 KB Output is correct
19 Correct 13 ms 23804 KB Output is correct
20 Correct 11 ms 23764 KB Output is correct
21 Correct 12 ms 23764 KB Output is correct
22 Correct 29 ms 27760 KB Output is correct
23 Correct 28 ms 27820 KB Output is correct
24 Correct 27 ms 27852 KB Output is correct
25 Correct 19 ms 24368 KB Output is correct
26 Correct 19 ms 24320 KB Output is correct
27 Correct 18 ms 24320 KB Output is correct
28 Correct 19 ms 24320 KB Output is correct
29 Correct 17 ms 24324 KB Output is correct
30 Correct 17 ms 24320 KB Output is correct
31 Correct 528 ms 25404 KB Output is correct
32 Correct 512 ms 25320 KB Output is correct
33 Correct 513 ms 25292 KB Output is correct
34 Correct 526 ms 25420 KB Output is correct
35 Correct 527 ms 25388 KB Output is correct
36 Correct 519 ms 25300 KB Output is correct
37 Correct 36 ms 28440 KB Output is correct
38 Correct 37 ms 28500 KB Output is correct
39 Correct 38 ms 28524 KB Output is correct
40 Correct 49 ms 26368 KB Output is correct
41 Correct 33 ms 25292 KB Output is correct
42 Correct 49 ms 26508 KB Output is correct
43 Correct 31 ms 25464 KB Output is correct
44 Correct 29 ms 25300 KB Output is correct
45 Correct 41 ms 26484 KB Output is correct
46 Execution timed out 1582 ms 33148 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23700 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 11 ms 23812 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 12 ms 23708 KB Output is correct
7 Correct 11 ms 23744 KB Output is correct
8 Correct 11 ms 23716 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 11 ms 23764 KB Output is correct
11 Correct 11 ms 23764 KB Output is correct
12 Correct 11 ms 23764 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 11 ms 23764 KB Output is correct
15 Correct 12 ms 23784 KB Output is correct
16 Correct 13 ms 23888 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 12 ms 23764 KB Output is correct
19 Correct 13 ms 23804 KB Output is correct
20 Correct 11 ms 23764 KB Output is correct
21 Correct 12 ms 23764 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 11 ms 23764 KB Output is correct
24 Correct 11 ms 23800 KB Output is correct
25 Correct 13 ms 23764 KB Output is correct
26 Correct 12 ms 23800 KB Output is correct
27 Correct 12 ms 23764 KB Output is correct
28 Correct 12 ms 23764 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 12 ms 23764 KB Output is correct
31 Correct 12 ms 23764 KB Output is correct
32 Correct 12 ms 23736 KB Output is correct
33 Correct 12 ms 23832 KB Output is correct
34 Correct 12 ms 23764 KB Output is correct
35 Correct 12 ms 23848 KB Output is correct
36 Correct 12 ms 23752 KB Output is correct
37 Correct 12 ms 23776 KB Output is correct
38 Correct 11 ms 23804 KB Output is correct
39 Correct 11 ms 23796 KB Output is correct
40 Correct 12 ms 23764 KB Output is correct
41 Correct 13 ms 23832 KB Output is correct
42 Correct 12 ms 23796 KB Output is correct
43 Correct 12 ms 23840 KB Output is correct
44 Correct 12 ms 23796 KB Output is correct
45 Correct 11 ms 23764 KB Output is correct
46 Correct 12 ms 23736 KB Output is correct
47 Correct 12 ms 23796 KB Output is correct
48 Correct 12 ms 23764 KB Output is correct
49 Correct 12 ms 23712 KB Output is correct
50 Correct 12 ms 23892 KB Output is correct
51 Correct 13 ms 23764 KB Output is correct
52 Correct 12 ms 23800 KB Output is correct
53 Correct 12 ms 23796 KB Output is correct
54 Correct 12 ms 23800 KB Output is correct
55 Correct 12 ms 23796 KB Output is correct
56 Correct 12 ms 23880 KB Output is correct
57 Correct 11 ms 23764 KB Output is correct
58 Correct 11 ms 23764 KB Output is correct
59 Correct 12 ms 23776 KB Output is correct
60 Correct 11 ms 23896 KB Output is correct
61 Correct 11 ms 23776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 11 ms 23700 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 11 ms 23812 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23708 KB Output is correct
9 Correct 11 ms 23744 KB Output is correct
10 Correct 11 ms 23716 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 11 ms 23764 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 11 ms 23764 KB Output is correct
15 Correct 11 ms 23764 KB Output is correct
16 Correct 11 ms 23764 KB Output is correct
17 Correct 12 ms 23784 KB Output is correct
18 Correct 13 ms 23888 KB Output is correct
19 Correct 12 ms 23800 KB Output is correct
20 Correct 12 ms 23764 KB Output is correct
21 Correct 13 ms 23804 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 12 ms 23764 KB Output is correct
24 Correct 29 ms 27760 KB Output is correct
25 Correct 28 ms 27820 KB Output is correct
26 Correct 27 ms 27852 KB Output is correct
27 Correct 11 ms 23800 KB Output is correct
28 Correct 13 ms 23764 KB Output is correct
29 Correct 12 ms 23800 KB Output is correct
30 Correct 12 ms 23764 KB Output is correct
31 Correct 12 ms 23764 KB Output is correct
32 Correct 12 ms 23764 KB Output is correct
33 Correct 12 ms 23764 KB Output is correct
34 Correct 12 ms 23764 KB Output is correct
35 Correct 12 ms 23736 KB Output is correct
36 Correct 12 ms 23832 KB Output is correct
37 Correct 12 ms 23764 KB Output is correct
38 Correct 12 ms 23848 KB Output is correct
39 Correct 12 ms 23752 KB Output is correct
40 Correct 12 ms 23776 KB Output is correct
41 Correct 11 ms 23804 KB Output is correct
42 Correct 11 ms 23796 KB Output is correct
43 Correct 12 ms 23764 KB Output is correct
44 Correct 13 ms 23832 KB Output is correct
45 Correct 12 ms 23796 KB Output is correct
46 Correct 12 ms 23840 KB Output is correct
47 Correct 12 ms 23796 KB Output is correct
48 Correct 11 ms 23764 KB Output is correct
49 Correct 12 ms 23736 KB Output is correct
50 Correct 12 ms 23796 KB Output is correct
51 Correct 12 ms 23764 KB Output is correct
52 Correct 12 ms 23712 KB Output is correct
53 Correct 12 ms 23892 KB Output is correct
54 Correct 13 ms 23764 KB Output is correct
55 Correct 12 ms 23800 KB Output is correct
56 Correct 12 ms 23796 KB Output is correct
57 Correct 12 ms 23800 KB Output is correct
58 Correct 12 ms 23796 KB Output is correct
59 Correct 12 ms 23880 KB Output is correct
60 Correct 11 ms 23764 KB Output is correct
61 Correct 11 ms 23764 KB Output is correct
62 Correct 12 ms 23776 KB Output is correct
63 Correct 11 ms 23896 KB Output is correct
64 Correct 11 ms 23776 KB Output is correct
65 Correct 12 ms 23804 KB Output is correct
66 Correct 12 ms 23776 KB Output is correct
67 Correct 12 ms 23804 KB Output is correct
68 Correct 11 ms 23776 KB Output is correct
69 Correct 12 ms 23836 KB Output is correct
70 Correct 17 ms 23980 KB Output is correct
71 Correct 17 ms 23956 KB Output is correct
72 Correct 16 ms 24068 KB Output is correct
73 Correct 13 ms 23936 KB Output is correct
74 Correct 16 ms 24020 KB Output is correct
75 Correct 16 ms 24020 KB Output is correct
76 Correct 31 ms 27072 KB Output is correct
77 Correct 48 ms 27620 KB Output is correct
78 Correct 34 ms 27908 KB Output is correct
79 Correct 11 ms 23764 KB Output is correct
80 Correct 12 ms 23836 KB Output is correct
81 Correct 12 ms 23764 KB Output is correct
82 Correct 12 ms 23764 KB Output is correct
83 Correct 12 ms 23792 KB Output is correct
84 Correct 19 ms 24020 KB Output is correct
85 Correct 20 ms 24020 KB Output is correct
86 Correct 20 ms 24148 KB Output is correct
87 Correct 22 ms 24020 KB Output is correct
88 Correct 20 ms 24020 KB Output is correct
89 Correct 19 ms 24148 KB Output is correct
90 Correct 36 ms 28116 KB Output is correct
91 Correct 36 ms 28080 KB Output is correct
92 Correct 37 ms 28112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 11 ms 23700 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 11 ms 23812 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23708 KB Output is correct
9 Correct 11 ms 23744 KB Output is correct
10 Correct 11 ms 23716 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 11 ms 23764 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 11 ms 23764 KB Output is correct
15 Correct 11 ms 23764 KB Output is correct
16 Correct 11 ms 23764 KB Output is correct
17 Correct 12 ms 23784 KB Output is correct
18 Correct 13 ms 23888 KB Output is correct
19 Correct 12 ms 23800 KB Output is correct
20 Correct 12 ms 23764 KB Output is correct
21 Correct 13 ms 23804 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 12 ms 23764 KB Output is correct
24 Correct 29 ms 27760 KB Output is correct
25 Correct 28 ms 27820 KB Output is correct
26 Correct 27 ms 27852 KB Output is correct
27 Correct 19 ms 24368 KB Output is correct
28 Correct 19 ms 24320 KB Output is correct
29 Correct 18 ms 24320 KB Output is correct
30 Correct 19 ms 24320 KB Output is correct
31 Correct 17 ms 24324 KB Output is correct
32 Correct 17 ms 24320 KB Output is correct
33 Correct 528 ms 25404 KB Output is correct
34 Correct 512 ms 25320 KB Output is correct
35 Correct 513 ms 25292 KB Output is correct
36 Correct 526 ms 25420 KB Output is correct
37 Correct 527 ms 25388 KB Output is correct
38 Correct 519 ms 25300 KB Output is correct
39 Correct 36 ms 28440 KB Output is correct
40 Correct 37 ms 28500 KB Output is correct
41 Correct 38 ms 28524 KB Output is correct
42 Correct 11 ms 23800 KB Output is correct
43 Correct 13 ms 23764 KB Output is correct
44 Correct 12 ms 23800 KB Output is correct
45 Correct 12 ms 23764 KB Output is correct
46 Correct 12 ms 23764 KB Output is correct
47 Correct 12 ms 23764 KB Output is correct
48 Correct 12 ms 23764 KB Output is correct
49 Correct 12 ms 23764 KB Output is correct
50 Correct 12 ms 23736 KB Output is correct
51 Correct 12 ms 23832 KB Output is correct
52 Correct 12 ms 23764 KB Output is correct
53 Correct 12 ms 23848 KB Output is correct
54 Correct 12 ms 23752 KB Output is correct
55 Correct 12 ms 23776 KB Output is correct
56 Correct 11 ms 23804 KB Output is correct
57 Correct 11 ms 23796 KB Output is correct
58 Correct 12 ms 23764 KB Output is correct
59 Correct 13 ms 23832 KB Output is correct
60 Correct 12 ms 23796 KB Output is correct
61 Correct 12 ms 23840 KB Output is correct
62 Correct 12 ms 23796 KB Output is correct
63 Correct 11 ms 23764 KB Output is correct
64 Correct 12 ms 23736 KB Output is correct
65 Correct 12 ms 23796 KB Output is correct
66 Correct 12 ms 23764 KB Output is correct
67 Correct 12 ms 23712 KB Output is correct
68 Correct 12 ms 23892 KB Output is correct
69 Correct 13 ms 23764 KB Output is correct
70 Correct 12 ms 23800 KB Output is correct
71 Correct 12 ms 23796 KB Output is correct
72 Correct 12 ms 23800 KB Output is correct
73 Correct 12 ms 23796 KB Output is correct
74 Correct 12 ms 23880 KB Output is correct
75 Correct 11 ms 23764 KB Output is correct
76 Correct 11 ms 23764 KB Output is correct
77 Correct 12 ms 23776 KB Output is correct
78 Correct 11 ms 23896 KB Output is correct
79 Correct 11 ms 23776 KB Output is correct
80 Correct 12 ms 23804 KB Output is correct
81 Correct 12 ms 23776 KB Output is correct
82 Correct 12 ms 23804 KB Output is correct
83 Correct 11 ms 23776 KB Output is correct
84 Correct 12 ms 23836 KB Output is correct
85 Correct 17 ms 23980 KB Output is correct
86 Correct 17 ms 23956 KB Output is correct
87 Correct 16 ms 24068 KB Output is correct
88 Correct 13 ms 23936 KB Output is correct
89 Correct 16 ms 24020 KB Output is correct
90 Correct 16 ms 24020 KB Output is correct
91 Correct 31 ms 27072 KB Output is correct
92 Correct 48 ms 27620 KB Output is correct
93 Correct 34 ms 27908 KB Output is correct
94 Correct 11 ms 23764 KB Output is correct
95 Correct 12 ms 23836 KB Output is correct
96 Correct 12 ms 23764 KB Output is correct
97 Correct 12 ms 23764 KB Output is correct
98 Correct 12 ms 23792 KB Output is correct
99 Correct 19 ms 24020 KB Output is correct
100 Correct 20 ms 24020 KB Output is correct
101 Correct 20 ms 24148 KB Output is correct
102 Correct 22 ms 24020 KB Output is correct
103 Correct 20 ms 24020 KB Output is correct
104 Correct 19 ms 24148 KB Output is correct
105 Correct 36 ms 28116 KB Output is correct
106 Correct 36 ms 28080 KB Output is correct
107 Correct 37 ms 28112 KB Output is correct
108 Correct 19 ms 24416 KB Output is correct
109 Correct 56 ms 24180 KB Output is correct
110 Correct 140 ms 24104 KB Output is correct
111 Correct 98 ms 24112 KB Output is correct
112 Correct 102 ms 24164 KB Output is correct
113 Correct 56 ms 24092 KB Output is correct
114 Correct 636 ms 25596 KB Output is correct
115 Correct 492 ms 25512 KB Output is correct
116 Correct 1118 ms 26056 KB Output is correct
117 Correct 563 ms 25676 KB Output is correct
118 Correct 604 ms 25684 KB Output is correct
119 Correct 569 ms 25420 KB Output is correct
120 Correct 29 ms 26956 KB Output is correct
121 Correct 208 ms 24596 KB Output is correct
122 Correct 48 ms 27240 KB Output is correct
123 Correct 132 ms 24496 KB Output is correct
124 Correct 61 ms 27852 KB Output is correct
125 Correct 185 ms 25048 KB Output is correct
126 Correct 124 ms 24920 KB Output is correct
127 Correct 257 ms 25336 KB Output is correct
128 Correct 115 ms 24852 KB Output is correct
129 Correct 133 ms 24864 KB Output is correct
130 Correct 19 ms 24320 KB Output is correct
131 Correct 80 ms 24472 KB Output is correct
132 Correct 216 ms 24424 KB Output is correct
133 Correct 146 ms 24396 KB Output is correct
134 Correct 119 ms 24360 KB Output is correct
135 Correct 105 ms 24372 KB Output is correct
136 Correct 1434 ms 26356 KB Output is correct
137 Execution timed out 1565 ms 26192 KB Time limit exceeded
138 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 11 ms 23700 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 11 ms 23812 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23708 KB Output is correct
9 Correct 11 ms 23744 KB Output is correct
10 Correct 11 ms 23716 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 11 ms 23764 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 11 ms 23764 KB Output is correct
15 Correct 11 ms 23764 KB Output is correct
16 Correct 11 ms 23764 KB Output is correct
17 Correct 12 ms 23784 KB Output is correct
18 Correct 13 ms 23888 KB Output is correct
19 Correct 12 ms 23800 KB Output is correct
20 Correct 12 ms 23764 KB Output is correct
21 Correct 13 ms 23804 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 12 ms 23764 KB Output is correct
24 Correct 29 ms 27760 KB Output is correct
25 Correct 28 ms 27820 KB Output is correct
26 Correct 27 ms 27852 KB Output is correct
27 Correct 19 ms 24368 KB Output is correct
28 Correct 19 ms 24320 KB Output is correct
29 Correct 18 ms 24320 KB Output is correct
30 Correct 19 ms 24320 KB Output is correct
31 Correct 17 ms 24324 KB Output is correct
32 Correct 17 ms 24320 KB Output is correct
33 Correct 528 ms 25404 KB Output is correct
34 Correct 512 ms 25320 KB Output is correct
35 Correct 513 ms 25292 KB Output is correct
36 Correct 526 ms 25420 KB Output is correct
37 Correct 527 ms 25388 KB Output is correct
38 Correct 519 ms 25300 KB Output is correct
39 Correct 36 ms 28440 KB Output is correct
40 Correct 37 ms 28500 KB Output is correct
41 Correct 38 ms 28524 KB Output is correct
42 Correct 49 ms 26368 KB Output is correct
43 Correct 33 ms 25292 KB Output is correct
44 Correct 49 ms 26508 KB Output is correct
45 Correct 31 ms 25464 KB Output is correct
46 Correct 29 ms 25300 KB Output is correct
47 Correct 41 ms 26484 KB Output is correct
48 Execution timed out 1582 ms 33148 KB Time limit exceeded
49 Halted 0 ms 0 KB -