답안 #714628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
714628 2023-03-25T06:46:24 Z MDSPro 벽 칠하기 (APIO20_paint) C++14
51 / 100
1117 ms 524288 KB
#include "paint.h"

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

const int INF = 1e9;
struct SegTree {
    int n,N;
    vector<int> tr;

    SegTree(int sz):n(sz){
        N = (1<<(32-__builtin_clz(n)));
        tr.assign(2*N,INF);
    }

    void upd(int idx, int val){
        for(idx += N, tr[idx] = val, idx >>= 1; idx > 0; idx >>= 1) tr[idx] = min(tr[idx<<1],tr[idx<<1|1]);
    }

    int get(int l, int r){
        int ans = INF;
        for(l += N, r += N; l < r; l >>= 1, r >>= 1){
            if(l&1) ans = min(tr[l++],ans);
            if(r&1) ans = min(ans,tr[--r]);
        }

        return ans;
    }
};

int minimumInstructions(int N, int M, int K, std::vector<int> C, std::vector<int> A, std::vector<std::vector<int>> B) {
    // [y,y+M-1]
    vector<vector<int>> contractors(K,vector<int>(0));
    for(int i = 0; i < M; ++i){
        for(int j = 0; j < A[i]; ++j){
            contractors[B[i][j]].emplace_back(i);
        }
    }
    //  M = 3 
    // [1 0 1]
    // [1 1 1]
    // [1 1 0]
    // [0 0 1] N-M = 3
    // [1 1 0]
    // [0 1 1]
    
    // TR
    // xy..y.x.y.....y....xy.x.x.y.x.x..y..xy..........
    // 
    vector<vector<int>> dp1(N, vector<int>(M,0));
    vector<pair<int,int>> segs;
    for(int y = N-1; y >= 0; --y){
        for(int x: contractors[C[y]]){
            if(y == N-1) dp1[y][x] = 1;
            else dp1[y][x] = dp1[y+1][(x+1)%M]+1;

            if(y <= N-M && dp1[y][x] >= M) segs.emplace_back(y,y+M-1);
        }
    }

    sort(segs.begin(),segs.end());

    SegTree sg(N);
    vector<int> dp(N,INF);
    for(auto z: segs){
        int l = z.first, r = z.second;
        if(l == 0) dp[r] = 1;
        else dp[r] = min(sg.get(l-1,r)+1,dp[r]);
        sg.upd(r,dp[r]);
    }

    if(dp[N-1] == INF) return -1;
    else return dp[N-1];
};


// O(N*M*logC+N*logN)
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 2 ms 3028 KB Output is correct
17 Correct 2 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 2 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 2 ms 3024 KB Output is correct
22 Correct 25 ms 6916 KB Output is correct
23 Correct 26 ms 6996 KB Output is correct
24 Correct 18 ms 6952 KB Output is correct
25 Correct 5 ms 2008 KB Output is correct
26 Correct 5 ms 2120 KB Output is correct
27 Correct 4 ms 2004 KB Output is correct
28 Correct 4 ms 1876 KB Output is correct
29 Correct 3 ms 1876 KB Output is correct
30 Correct 4 ms 1876 KB Output is correct
31 Correct 72 ms 161568 KB Output is correct
32 Correct 74 ms 161584 KB Output is correct
33 Correct 79 ms 161520 KB Output is correct
34 Correct 79 ms 161540 KB Output is correct
35 Correct 74 ms 161504 KB Output is correct
36 Correct 77 ms 161556 KB Output is correct
37 Correct 85 ms 164452 KB Output is correct
38 Correct 87 ms 165212 KB Output is correct
39 Correct 87 ms 165224 KB Output is correct
40 Correct 19 ms 8184 KB Output is correct
41 Correct 13 ms 5112 KB Output is correct
42 Correct 24 ms 8480 KB Output is correct
43 Correct 11 ms 5412 KB Output is correct
44 Correct 9 ms 4820 KB Output is correct
45 Correct 16 ms 8116 KB Output is correct
46 Runtime error 238 ms 524288 KB Execution killed with signal 9
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 2 ms 3028 KB Output is correct
17 Correct 2 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 2 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 2 ms 3024 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 296 KB Output is correct
26 Correct 1 ms 300 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 2 ms 472 KB Output is correct
29 Correct 2 ms 300 KB Output is correct
30 Correct 1 ms 296 KB Output is correct
31 Correct 1 ms 296 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 2516 KB Output is correct
34 Correct 2 ms 2132 KB Output is correct
35 Correct 1 ms 1748 KB Output is correct
36 Correct 2 ms 2864 KB Output is correct
37 Correct 2 ms 2388 KB Output is correct
38 Correct 2 ms 2356 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 2 ms 2308 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 2 ms 2516 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 556 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 424 KB Output is correct
50 Correct 3 ms 3116 KB Output is correct
51 Correct 2 ms 3028 KB Output is correct
52 Correct 2 ms 3028 KB Output is correct
53 Correct 3 ms 3124 KB Output is correct
54 Correct 2 ms 3028 KB Output is correct
55 Correct 2 ms 3120 KB Output is correct
56 Correct 2 ms 3028 KB Output is correct
57 Correct 1 ms 724 KB Output is correct
58 Correct 3 ms 3124 KB Output is correct
59 Correct 2 ms 724 KB Output is correct
60 Correct 3 ms 3028 KB Output is correct
61 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 2 ms 3028 KB Output is correct
17 Correct 2 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 2 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 2 ms 3024 KB Output is correct
24 Correct 25 ms 6916 KB Output is correct
25 Correct 26 ms 6996 KB Output is correct
26 Correct 18 ms 6952 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 296 KB Output is correct
29 Correct 1 ms 300 KB Output is correct
30 Correct 1 ms 300 KB Output is correct
31 Correct 2 ms 472 KB Output is correct
32 Correct 2 ms 300 KB Output is correct
33 Correct 1 ms 296 KB Output is correct
34 Correct 1 ms 296 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2 ms 2516 KB Output is correct
37 Correct 2 ms 2132 KB Output is correct
38 Correct 1 ms 1748 KB Output is correct
39 Correct 2 ms 2864 KB Output is correct
40 Correct 2 ms 2388 KB Output is correct
41 Correct 2 ms 2356 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 2 ms 2308 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 2 ms 2516 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 2 ms 556 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 424 KB Output is correct
53 Correct 3 ms 3116 KB Output is correct
54 Correct 2 ms 3028 KB Output is correct
55 Correct 2 ms 3028 KB Output is correct
56 Correct 3 ms 3124 KB Output is correct
57 Correct 2 ms 3028 KB Output is correct
58 Correct 2 ms 3120 KB Output is correct
59 Correct 2 ms 3028 KB Output is correct
60 Correct 1 ms 724 KB Output is correct
61 Correct 3 ms 3124 KB Output is correct
62 Correct 2 ms 724 KB Output is correct
63 Correct 3 ms 3028 KB Output is correct
64 Correct 2 ms 724 KB Output is correct
65 Correct 2 ms 724 KB Output is correct
66 Correct 2 ms 724 KB Output is correct
67 Correct 4 ms 1104 KB Output is correct
68 Correct 2 ms 852 KB Output is correct
69 Correct 3 ms 1108 KB Output is correct
70 Correct 3 ms 2772 KB Output is correct
71 Correct 3 ms 2400 KB Output is correct
72 Correct 3 ms 2004 KB Output is correct
73 Correct 3 ms 2132 KB Output is correct
74 Correct 3 ms 2476 KB Output is correct
75 Correct 3 ms 3028 KB Output is correct
76 Correct 20 ms 4804 KB Output is correct
77 Correct 23 ms 5528 KB Output is correct
78 Correct 26 ms 6196 KB Output is correct
79 Correct 6 ms 1360 KB Output is correct
80 Correct 5 ms 1360 KB Output is correct
81 Correct 5 ms 1360 KB Output is correct
82 Correct 5 ms 1360 KB Output is correct
83 Correct 5 ms 1360 KB Output is correct
84 Correct 4 ms 3312 KB Output is correct
85 Correct 4 ms 3284 KB Output is correct
86 Correct 4 ms 3284 KB Output is correct
87 Correct 4 ms 3288 KB Output is correct
88 Correct 4 ms 3284 KB Output is correct
89 Correct 4 ms 3284 KB Output is correct
90 Correct 31 ms 6860 KB Output is correct
91 Correct 29 ms 6952 KB Output is correct
92 Correct 32 ms 7016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 2 ms 3028 KB Output is correct
17 Correct 2 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 2 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 2 ms 3024 KB Output is correct
24 Correct 25 ms 6916 KB Output is correct
25 Correct 26 ms 6996 KB Output is correct
26 Correct 18 ms 6952 KB Output is correct
27 Correct 5 ms 2008 KB Output is correct
28 Correct 5 ms 2120 KB Output is correct
29 Correct 4 ms 2004 KB Output is correct
30 Correct 4 ms 1876 KB Output is correct
31 Correct 3 ms 1876 KB Output is correct
32 Correct 4 ms 1876 KB Output is correct
33 Correct 72 ms 161568 KB Output is correct
34 Correct 74 ms 161584 KB Output is correct
35 Correct 79 ms 161520 KB Output is correct
36 Correct 79 ms 161540 KB Output is correct
37 Correct 74 ms 161504 KB Output is correct
38 Correct 77 ms 161556 KB Output is correct
39 Correct 85 ms 164452 KB Output is correct
40 Correct 87 ms 165212 KB Output is correct
41 Correct 87 ms 165224 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 296 KB Output is correct
44 Correct 1 ms 300 KB Output is correct
45 Correct 1 ms 300 KB Output is correct
46 Correct 2 ms 472 KB Output is correct
47 Correct 2 ms 300 KB Output is correct
48 Correct 1 ms 296 KB Output is correct
49 Correct 1 ms 296 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 2 ms 2516 KB Output is correct
52 Correct 2 ms 2132 KB Output is correct
53 Correct 1 ms 1748 KB Output is correct
54 Correct 2 ms 2864 KB Output is correct
55 Correct 2 ms 2388 KB Output is correct
56 Correct 2 ms 2356 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 2 ms 2308 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 2 ms 2644 KB Output is correct
61 Correct 2 ms 2516 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 2 ms 556 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 424 KB Output is correct
68 Correct 3 ms 3116 KB Output is correct
69 Correct 2 ms 3028 KB Output is correct
70 Correct 2 ms 3028 KB Output is correct
71 Correct 3 ms 3124 KB Output is correct
72 Correct 2 ms 3028 KB Output is correct
73 Correct 2 ms 3120 KB Output is correct
74 Correct 2 ms 3028 KB Output is correct
75 Correct 1 ms 724 KB Output is correct
76 Correct 3 ms 3124 KB Output is correct
77 Correct 2 ms 724 KB Output is correct
78 Correct 3 ms 3028 KB Output is correct
79 Correct 2 ms 724 KB Output is correct
80 Correct 2 ms 724 KB Output is correct
81 Correct 2 ms 724 KB Output is correct
82 Correct 4 ms 1104 KB Output is correct
83 Correct 2 ms 852 KB Output is correct
84 Correct 3 ms 1108 KB Output is correct
85 Correct 3 ms 2772 KB Output is correct
86 Correct 3 ms 2400 KB Output is correct
87 Correct 3 ms 2004 KB Output is correct
88 Correct 3 ms 2132 KB Output is correct
89 Correct 3 ms 2476 KB Output is correct
90 Correct 3 ms 3028 KB Output is correct
91 Correct 20 ms 4804 KB Output is correct
92 Correct 23 ms 5528 KB Output is correct
93 Correct 26 ms 6196 KB Output is correct
94 Correct 6 ms 1360 KB Output is correct
95 Correct 5 ms 1360 KB Output is correct
96 Correct 5 ms 1360 KB Output is correct
97 Correct 5 ms 1360 KB Output is correct
98 Correct 5 ms 1360 KB Output is correct
99 Correct 4 ms 3312 KB Output is correct
100 Correct 4 ms 3284 KB Output is correct
101 Correct 4 ms 3284 KB Output is correct
102 Correct 4 ms 3288 KB Output is correct
103 Correct 4 ms 3284 KB Output is correct
104 Correct 4 ms 3284 KB Output is correct
105 Correct 31 ms 6860 KB Output is correct
106 Correct 29 ms 6952 KB Output is correct
107 Correct 32 ms 7016 KB Output is correct
108 Correct 6 ms 2136 KB Output is correct
109 Correct 760 ms 167516 KB Output is correct
110 Correct 40 ms 32096 KB Output is correct
111 Correct 34 ms 31588 KB Output is correct
112 Correct 43 ms 45132 KB Output is correct
113 Correct 34 ms 41096 KB Output is correct
114 Correct 33 ms 48080 KB Output is correct
115 Correct 16 ms 7352 KB Output is correct
116 Correct 45 ms 57296 KB Output is correct
117 Correct 26 ms 33628 KB Output is correct
118 Correct 18 ms 9544 KB Output is correct
119 Correct 47 ms 88720 KB Output is correct
120 Correct 55 ms 96304 KB Output is correct
121 Correct 43 ms 92896 KB Output is correct
122 Correct 42 ms 30900 KB Output is correct
123 Correct 18 ms 27220 KB Output is correct
124 Correct 35 ms 18508 KB Output is correct
125 Correct 15 ms 14300 KB Output is correct
126 Correct 8 ms 4436 KB Output is correct
127 Correct 28 ms 43204 KB Output is correct
128 Correct 11 ms 10572 KB Output is correct
129 Correct 13 ms 13764 KB Output is correct
130 Correct 6 ms 2184 KB Output is correct
131 Correct 1117 ms 182236 KB Output is correct
132 Correct 86 ms 64300 KB Output is correct
133 Correct 73 ms 72496 KB Output is correct
134 Correct 68 ms 79004 KB Output is correct
135 Correct 66 ms 85028 KB Output is correct
136 Correct 83 ms 162640 KB Output is correct
137 Correct 92 ms 162608 KB Output is correct
138 Correct 80 ms 162664 KB Output is correct
139 Correct 82 ms 162632 KB Output is correct
140 Correct 85 ms 162752 KB Output is correct
141 Correct 85 ms 162604 KB Output is correct
142 Correct 103 ms 165352 KB Output is correct
143 Correct 72 ms 159668 KB Output is correct
144 Correct 94 ms 165300 KB Output is correct
145 Correct 74 ms 159636 KB Output is correct
146 Correct 96 ms 165332 KB Output is correct
147 Correct 79 ms 159708 KB Output is correct
148 Correct 73 ms 161952 KB Output is correct
149 Correct 43 ms 83400 KB Output is correct
150 Correct 33 ms 56996 KB Output is correct
151 Correct 27 ms 44184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 2 ms 3028 KB Output is correct
17 Correct 2 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 2 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 2 ms 3024 KB Output is correct
24 Correct 25 ms 6916 KB Output is correct
25 Correct 26 ms 6996 KB Output is correct
26 Correct 18 ms 6952 KB Output is correct
27 Correct 5 ms 2008 KB Output is correct
28 Correct 5 ms 2120 KB Output is correct
29 Correct 4 ms 2004 KB Output is correct
30 Correct 4 ms 1876 KB Output is correct
31 Correct 3 ms 1876 KB Output is correct
32 Correct 4 ms 1876 KB Output is correct
33 Correct 72 ms 161568 KB Output is correct
34 Correct 74 ms 161584 KB Output is correct
35 Correct 79 ms 161520 KB Output is correct
36 Correct 79 ms 161540 KB Output is correct
37 Correct 74 ms 161504 KB Output is correct
38 Correct 77 ms 161556 KB Output is correct
39 Correct 85 ms 164452 KB Output is correct
40 Correct 87 ms 165212 KB Output is correct
41 Correct 87 ms 165224 KB Output is correct
42 Correct 19 ms 8184 KB Output is correct
43 Correct 13 ms 5112 KB Output is correct
44 Correct 24 ms 8480 KB Output is correct
45 Correct 11 ms 5412 KB Output is correct
46 Correct 9 ms 4820 KB Output is correct
47 Correct 16 ms 8116 KB Output is correct
48 Runtime error 238 ms 524288 KB Execution killed with signal 9
49 Halted 0 ms 0 KB -