답안 #567170

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567170 2022-05-23T08:47:38 Z Belgutei 벽 칠하기 (APIO20_paint) C++17
51 / 100
1500 ms 13856 KB
#include "paint.h"
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define X real()
#define Y imag()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define MOD 1000000007
#define MOD1 1000000009
#define sqr(x) sqr((x)*(x))
 
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
#ifdef BE_DEBUG
#define debug(...) cerr << "\033[1;31m(" << #__VA_ARGS__ << "):\033[0m", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

vector<int> v[100005];
int tur[100005];
int cnt[100005];

ll dp[100005];
 
int minimumInstructions( int N, int M, int K, std::vector<int> C, std::vector<int> A, std::vector<std::vector<int>> B) {
    for(int i = 0; i < M; i ++) {
        for(int j = 0; j < B[i].size(); j ++) {
            // i-th person likes to paint color B[i][j]
            v[B[i][j]].pb(i);
        }
    }
    for(int i = 0; i < N; i ++) dp[i] = 1e9;
    for(int i = 0; i < N; i ++) {
        for(int j = 0; j < M; j ++){
            tur[j] = cnt[j];
            cnt[j] = 0;
        }
        bool check = 0;
        for(auto x: v[C[i]]) {
            int pre = x - 1;

            if(pre == -1) pre = M - 1;
            if(tur[pre] + 1 >= M) {
                check = 1;
                cnt[x] = M;
            }
            else {
                cnt[x] = max(cnt[x], tur[pre] + 1);
            }
        }
        
        if(check == 1) {
            if(i == M - 1) {
                dp[i] = 1;
            }
            for(int j = i - 1; j >= max(i - M,0); j --) {
                dp[i] = min(dp[i], dp[j] + 1);
            }
        }
    }
    if(dp[N - 1] >= 1e9) return -1;
    return dp[N - 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:34:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(int j = 0; j < B[i].size(); j ++) {
      |                        ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2600 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2648 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 3 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 24 ms 6576 KB Output is correct
23 Correct 24 ms 6484 KB Output is correct
24 Correct 21 ms 6484 KB Output is correct
25 Correct 3 ms 2900 KB Output is correct
26 Correct 3 ms 2928 KB Output is correct
27 Correct 4 ms 2900 KB Output is correct
28 Correct 4 ms 2864 KB Output is correct
29 Correct 3 ms 2900 KB Output is correct
30 Correct 4 ms 2900 KB Output is correct
31 Correct 61 ms 3796 KB Output is correct
32 Correct 63 ms 4132 KB Output is correct
33 Correct 68 ms 4148 KB Output is correct
34 Correct 68 ms 4104 KB Output is correct
35 Correct 57 ms 4076 KB Output is correct
36 Correct 55 ms 4128 KB Output is correct
37 Correct 31 ms 7748 KB Output is correct
38 Correct 29 ms 7744 KB Output is correct
39 Correct 38 ms 7628 KB Output is correct
40 Correct 13 ms 4224 KB Output is correct
41 Correct 8 ms 3564 KB Output is correct
42 Correct 12 ms 4332 KB Output is correct
43 Correct 8 ms 3916 KB Output is correct
44 Correct 8 ms 3668 KB Output is correct
45 Correct 11 ms 4308 KB Output is correct
46 Execution timed out 1574 ms 13856 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2600 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2648 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 3 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 3 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 2 ms 2644 KB Output is correct
34 Correct 3 ms 2644 KB Output is correct
35 Correct 2 ms 2644 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 2 ms 2704 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 2 ms 2644 KB Output is correct
41 Correct 2 ms 2644 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 2 ms 2644 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 3 ms 2644 KB Output is correct
50 Correct 2 ms 2644 KB Output is correct
51 Correct 2 ms 2656 KB Output is correct
52 Correct 2 ms 2644 KB Output is correct
53 Correct 2 ms 2644 KB Output is correct
54 Correct 3 ms 2644 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2636 KB Output is correct
57 Correct 2 ms 2644 KB Output is correct
58 Correct 2 ms 2644 KB Output is correct
59 Correct 2 ms 2644 KB Output is correct
60 Correct 1 ms 2644 KB Output is correct
61 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 3 ms 2600 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 24 ms 6576 KB Output is correct
25 Correct 24 ms 6484 KB Output is correct
26 Correct 21 ms 6484 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 1 ms 2644 KB Output is correct
34 Correct 2 ms 2644 KB Output is correct
35 Correct 2 ms 2644 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 3 ms 2644 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 2 ms 2704 KB Output is correct
41 Correct 2 ms 2644 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 2 ms 2644 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 2 ms 2644 KB Output is correct
50 Correct 2 ms 2644 KB Output is correct
51 Correct 2 ms 2644 KB Output is correct
52 Correct 3 ms 2644 KB Output is correct
53 Correct 2 ms 2644 KB Output is correct
54 Correct 2 ms 2656 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 3 ms 2644 KB Output is correct
58 Correct 2 ms 2644 KB Output is correct
59 Correct 2 ms 2636 KB Output is correct
60 Correct 2 ms 2644 KB Output is correct
61 Correct 2 ms 2644 KB Output is correct
62 Correct 2 ms 2644 KB Output is correct
63 Correct 1 ms 2644 KB Output is correct
64 Correct 2 ms 2644 KB Output is correct
65 Correct 2 ms 2644 KB Output is correct
66 Correct 2 ms 2644 KB Output is correct
67 Correct 2 ms 2644 KB Output is correct
68 Correct 2 ms 2644 KB Output is correct
69 Correct 2 ms 2644 KB Output is correct
70 Correct 4 ms 2772 KB Output is correct
71 Correct 3 ms 2820 KB Output is correct
72 Correct 4 ms 2772 KB Output is correct
73 Correct 2 ms 2772 KB Output is correct
74 Correct 4 ms 2772 KB Output is correct
75 Correct 3 ms 2772 KB Output is correct
76 Correct 19 ms 5232 KB Output is correct
77 Correct 18 ms 5716 KB Output is correct
78 Correct 23 ms 6100 KB Output is correct
79 Correct 3 ms 2644 KB Output is correct
80 Correct 2 ms 2644 KB Output is correct
81 Correct 3 ms 2644 KB Output is correct
82 Correct 2 ms 2612 KB Output is correct
83 Correct 2 ms 2644 KB Output is correct
84 Correct 3 ms 2900 KB Output is correct
85 Correct 4 ms 2900 KB Output is correct
86 Correct 4 ms 2772 KB Output is correct
87 Correct 5 ms 2900 KB Output is correct
88 Correct 4 ms 2900 KB Output is correct
89 Correct 4 ms 2900 KB Output is correct
90 Correct 28 ms 6336 KB Output is correct
91 Correct 27 ms 6340 KB Output is correct
92 Correct 29 ms 6424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 3 ms 2600 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 24 ms 6576 KB Output is correct
25 Correct 24 ms 6484 KB Output is correct
26 Correct 21 ms 6484 KB Output is correct
27 Correct 3 ms 2900 KB Output is correct
28 Correct 3 ms 2928 KB Output is correct
29 Correct 4 ms 2900 KB Output is correct
30 Correct 4 ms 2864 KB Output is correct
31 Correct 3 ms 2900 KB Output is correct
32 Correct 4 ms 2900 KB Output is correct
33 Correct 61 ms 3796 KB Output is correct
34 Correct 63 ms 4132 KB Output is correct
35 Correct 68 ms 4148 KB Output is correct
36 Correct 68 ms 4104 KB Output is correct
37 Correct 57 ms 4076 KB Output is correct
38 Correct 55 ms 4128 KB Output is correct
39 Correct 31 ms 7748 KB Output is correct
40 Correct 29 ms 7744 KB Output is correct
41 Correct 38 ms 7628 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 1 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 2 ms 2644 KB Output is correct
48 Correct 1 ms 2644 KB Output is correct
49 Correct 2 ms 2644 KB Output is correct
50 Correct 2 ms 2644 KB Output is correct
51 Correct 2 ms 2644 KB Output is correct
52 Correct 3 ms 2644 KB Output is correct
53 Correct 2 ms 2644 KB Output is correct
54 Correct 2 ms 2644 KB Output is correct
55 Correct 2 ms 2704 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 2 ms 2644 KB Output is correct
58 Correct 2 ms 2644 KB Output is correct
59 Correct 2 ms 2644 KB Output is correct
60 Correct 2 ms 2644 KB Output is correct
61 Correct 2 ms 2644 KB Output is correct
62 Correct 2 ms 2644 KB Output is correct
63 Correct 2 ms 2644 KB Output is correct
64 Correct 2 ms 2644 KB Output is correct
65 Correct 2 ms 2644 KB Output is correct
66 Correct 2 ms 2644 KB Output is correct
67 Correct 3 ms 2644 KB Output is correct
68 Correct 2 ms 2644 KB Output is correct
69 Correct 2 ms 2656 KB Output is correct
70 Correct 2 ms 2644 KB Output is correct
71 Correct 2 ms 2644 KB Output is correct
72 Correct 3 ms 2644 KB Output is correct
73 Correct 2 ms 2644 KB Output is correct
74 Correct 2 ms 2636 KB Output is correct
75 Correct 2 ms 2644 KB Output is correct
76 Correct 2 ms 2644 KB Output is correct
77 Correct 2 ms 2644 KB Output is correct
78 Correct 1 ms 2644 KB Output is correct
79 Correct 2 ms 2644 KB Output is correct
80 Correct 2 ms 2644 KB Output is correct
81 Correct 2 ms 2644 KB Output is correct
82 Correct 2 ms 2644 KB Output is correct
83 Correct 2 ms 2644 KB Output is correct
84 Correct 2 ms 2644 KB Output is correct
85 Correct 4 ms 2772 KB Output is correct
86 Correct 3 ms 2820 KB Output is correct
87 Correct 4 ms 2772 KB Output is correct
88 Correct 2 ms 2772 KB Output is correct
89 Correct 4 ms 2772 KB Output is correct
90 Correct 3 ms 2772 KB Output is correct
91 Correct 19 ms 5232 KB Output is correct
92 Correct 18 ms 5716 KB Output is correct
93 Correct 23 ms 6100 KB Output is correct
94 Correct 3 ms 2644 KB Output is correct
95 Correct 2 ms 2644 KB Output is correct
96 Correct 3 ms 2644 KB Output is correct
97 Correct 2 ms 2612 KB Output is correct
98 Correct 2 ms 2644 KB Output is correct
99 Correct 3 ms 2900 KB Output is correct
100 Correct 4 ms 2900 KB Output is correct
101 Correct 4 ms 2772 KB Output is correct
102 Correct 5 ms 2900 KB Output is correct
103 Correct 4 ms 2900 KB Output is correct
104 Correct 4 ms 2900 KB Output is correct
105 Correct 28 ms 6336 KB Output is correct
106 Correct 27 ms 6340 KB Output is correct
107 Correct 29 ms 6424 KB Output is correct
108 Correct 4 ms 2920 KB Output is correct
109 Correct 38 ms 2976 KB Output is correct
110 Correct 20 ms 2968 KB Output is correct
111 Correct 16 ms 2964 KB Output is correct
112 Correct 20 ms 3164 KB Output is correct
113 Correct 14 ms 2900 KB Output is correct
114 Correct 29 ms 4308 KB Output is correct
115 Correct 15 ms 4156 KB Output is correct
116 Correct 34 ms 4644 KB Output is correct
117 Correct 24 ms 4332 KB Output is correct
118 Correct 18 ms 4436 KB Output is correct
119 Correct 51 ms 4112 KB Output is correct
120 Correct 24 ms 5804 KB Output is correct
121 Correct 34 ms 3384 KB Output is correct
122 Correct 24 ms 6096 KB Output is correct
123 Correct 14 ms 3256 KB Output is correct
124 Correct 25 ms 6668 KB Output is correct
125 Correct 11 ms 3684 KB Output is correct
126 Correct 8 ms 3720 KB Output is correct
127 Correct 12 ms 3984 KB Output is correct
128 Correct 9 ms 3668 KB Output is correct
129 Correct 10 ms 3692 KB Output is correct
130 Correct 3 ms 2900 KB Output is correct
131 Correct 58 ms 3052 KB Output is correct
132 Correct 35 ms 3028 KB Output is correct
133 Correct 31 ms 3028 KB Output is correct
134 Correct 27 ms 3156 KB Output is correct
135 Correct 26 ms 3156 KB Output is correct
136 Correct 68 ms 4952 KB Output is correct
137 Correct 72 ms 4924 KB Output is correct
138 Correct 71 ms 4976 KB Output is correct
139 Correct 69 ms 4948 KB Output is correct
140 Correct 68 ms 4936 KB Output is correct
141 Correct 65 ms 4948 KB Output is correct
142 Correct 41 ms 7888 KB Output is correct
143 Correct 61 ms 3888 KB Output is correct
144 Correct 54 ms 7800 KB Output is correct
145 Correct 57 ms 3880 KB Output is correct
146 Correct 39 ms 7772 KB Output is correct
147 Correct 57 ms 3884 KB Output is correct
148 Correct 20 ms 4380 KB Output is correct
149 Correct 22 ms 4216 KB Output is correct
150 Correct 14 ms 4100 KB Output is correct
151 Correct 13 ms 4036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 3 ms 2600 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 24 ms 6576 KB Output is correct
25 Correct 24 ms 6484 KB Output is correct
26 Correct 21 ms 6484 KB Output is correct
27 Correct 3 ms 2900 KB Output is correct
28 Correct 3 ms 2928 KB Output is correct
29 Correct 4 ms 2900 KB Output is correct
30 Correct 4 ms 2864 KB Output is correct
31 Correct 3 ms 2900 KB Output is correct
32 Correct 4 ms 2900 KB Output is correct
33 Correct 61 ms 3796 KB Output is correct
34 Correct 63 ms 4132 KB Output is correct
35 Correct 68 ms 4148 KB Output is correct
36 Correct 68 ms 4104 KB Output is correct
37 Correct 57 ms 4076 KB Output is correct
38 Correct 55 ms 4128 KB Output is correct
39 Correct 31 ms 7748 KB Output is correct
40 Correct 29 ms 7744 KB Output is correct
41 Correct 38 ms 7628 KB Output is correct
42 Correct 13 ms 4224 KB Output is correct
43 Correct 8 ms 3564 KB Output is correct
44 Correct 12 ms 4332 KB Output is correct
45 Correct 8 ms 3916 KB Output is correct
46 Correct 8 ms 3668 KB Output is correct
47 Correct 11 ms 4308 KB Output is correct
48 Execution timed out 1574 ms 13856 KB Time limit exceeded
49 Halted 0 ms 0 KB -