#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 13;
vector<int> v[N];
int dp[N],n,lst[N],val[N];
int minimumInstructions(int nn, int m, int k,vector<int> C,vector<int> A,vector<vector<int>> B) {
n = nn;
for(int i = 0;i < m;i++){
for(int j:B[i]){
v[j].push_back(i);
}
}
set<int> st;
const int inf = 1e9;
st.insert(n);
for(int i = n - 1;i >= 0;i--){
bool ok = false;
for(int j:v[C[i]]){
int nx = j + 1;
if(j + 1==m) nx = 0;
if(lst[nx] == i + 1){
val[j] = val[nx] + 1;
}else{
val[j] = 1;
}
if(val[j] >= m){
ok = true;
}
}
for(int j:v[C[i]]){
lst[j] = i;
}
if(ok){
dp[i] = inf;
for(int j = i + 1;j <= min(n,i + m);j++){
if(dp[j] != inf){
dp[i] = min(dp[i],dp[j] + 1);
}
}
}else{
dp[i] =inf;
continue;
}
// auto it = st.upper_bound(i + m);
// if(it == st.begin()){
// st.erase(i);
// dp[i] = inf;continue;
// }
// it--;
// dp[i] = dp[*it] + 1;
}
return (dp[0] < inf? dp[0]:-1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23900 KB |
Output is correct |
2 |
Correct |
13 ms |
23908 KB |
Output is correct |
3 |
Correct |
10 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
23700 KB |
Output is correct |
6 |
Correct |
10 ms |
23896 KB |
Output is correct |
7 |
Correct |
11 ms |
23900 KB |
Output is correct |
8 |
Correct |
12 ms |
23896 KB |
Output is correct |
9 |
Correct |
11 ms |
23908 KB |
Output is correct |
10 |
Correct |
10 ms |
23896 KB |
Output is correct |
11 |
Correct |
10 ms |
23900 KB |
Output is correct |
12 |
Correct |
13 ms |
23948 KB |
Output is correct |
13 |
Correct |
10 ms |
23900 KB |
Output is correct |
14 |
Correct |
11 ms |
23896 KB |
Output is correct |
15 |
Correct |
14 ms |
23900 KB |
Output is correct |
16 |
Correct |
14 ms |
24004 KB |
Output is correct |
17 |
Correct |
11 ms |
23896 KB |
Output is correct |
18 |
Correct |
10 ms |
23900 KB |
Output is correct |
19 |
Correct |
10 ms |
23896 KB |
Output is correct |
20 |
Correct |
10 ms |
23900 KB |
Output is correct |
21 |
Correct |
10 ms |
23904 KB |
Output is correct |
22 |
Correct |
23 ms |
28368 KB |
Output is correct |
23 |
Correct |
31 ms |
28248 KB |
Output is correct |
24 |
Correct |
26 ms |
28300 KB |
Output is correct |
25 |
Correct |
15 ms |
24060 KB |
Output is correct |
26 |
Correct |
14 ms |
24048 KB |
Output is correct |
27 |
Correct |
11 ms |
24156 KB |
Output is correct |
28 |
Correct |
12 ms |
24124 KB |
Output is correct |
29 |
Correct |
11 ms |
24408 KB |
Output is correct |
30 |
Correct |
11 ms |
24140 KB |
Output is correct |
31 |
Correct |
44 ms |
25176 KB |
Output is correct |
32 |
Correct |
42 ms |
25180 KB |
Output is correct |
33 |
Correct |
40 ms |
25432 KB |
Output is correct |
34 |
Correct |
41 ms |
25176 KB |
Output is correct |
35 |
Correct |
42 ms |
25284 KB |
Output is correct |
36 |
Correct |
58 ms |
25180 KB |
Output is correct |
37 |
Correct |
26 ms |
28764 KB |
Output is correct |
38 |
Correct |
25 ms |
28764 KB |
Output is correct |
39 |
Correct |
29 ms |
28756 KB |
Output is correct |
40 |
Correct |
16 ms |
25176 KB |
Output is correct |
41 |
Correct |
13 ms |
24668 KB |
Output is correct |
42 |
Correct |
18 ms |
25232 KB |
Output is correct |
43 |
Correct |
14 ms |
24664 KB |
Output is correct |
44 |
Correct |
14 ms |
24668 KB |
Output is correct |
45 |
Correct |
18 ms |
25300 KB |
Output is correct |
46 |
Correct |
1350 ms |
34900 KB |
Output is correct |
47 |
Correct |
601 ms |
30036 KB |
Output is correct |
48 |
Correct |
316 ms |
32600 KB |
Output is correct |
49 |
Correct |
33 ms |
33052 KB |
Output is correct |
50 |
Correct |
35 ms |
32596 KB |
Output is correct |
51 |
Correct |
30 ms |
30288 KB |
Output is correct |
52 |
Correct |
15 ms |
25180 KB |
Output is correct |
53 |
Correct |
17 ms |
25176 KB |
Output is correct |
54 |
Correct |
17 ms |
25176 KB |
Output is correct |
55 |
Correct |
18 ms |
25180 KB |
Output is correct |
56 |
Correct |
17 ms |
25288 KB |
Output is correct |
57 |
Correct |
16 ms |
25180 KB |
Output is correct |
58 |
Execution timed out |
1528 ms |
35664 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23900 KB |
Output is correct |
2 |
Correct |
13 ms |
23908 KB |
Output is correct |
3 |
Correct |
10 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
23700 KB |
Output is correct |
6 |
Correct |
10 ms |
23896 KB |
Output is correct |
7 |
Correct |
11 ms |
23900 KB |
Output is correct |
8 |
Correct |
12 ms |
23896 KB |
Output is correct |
9 |
Correct |
11 ms |
23908 KB |
Output is correct |
10 |
Correct |
10 ms |
23896 KB |
Output is correct |
11 |
Correct |
10 ms |
23900 KB |
Output is correct |
12 |
Correct |
13 ms |
23948 KB |
Output is correct |
13 |
Correct |
10 ms |
23900 KB |
Output is correct |
14 |
Correct |
11 ms |
23896 KB |
Output is correct |
15 |
Correct |
14 ms |
23900 KB |
Output is correct |
16 |
Correct |
14 ms |
24004 KB |
Output is correct |
17 |
Correct |
11 ms |
23896 KB |
Output is correct |
18 |
Correct |
10 ms |
23900 KB |
Output is correct |
19 |
Correct |
10 ms |
23896 KB |
Output is correct |
20 |
Correct |
10 ms |
23900 KB |
Output is correct |
21 |
Correct |
10 ms |
23904 KB |
Output is correct |
22 |
Correct |
11 ms |
23896 KB |
Output is correct |
23 |
Correct |
10 ms |
23900 KB |
Output is correct |
24 |
Correct |
10 ms |
23900 KB |
Output is correct |
25 |
Correct |
10 ms |
23896 KB |
Output is correct |
26 |
Correct |
9 ms |
23840 KB |
Output is correct |
27 |
Correct |
11 ms |
23900 KB |
Output is correct |
28 |
Correct |
10 ms |
23776 KB |
Output is correct |
29 |
Correct |
10 ms |
23952 KB |
Output is correct |
30 |
Correct |
10 ms |
23900 KB |
Output is correct |
31 |
Correct |
10 ms |
23836 KB |
Output is correct |
32 |
Correct |
10 ms |
23928 KB |
Output is correct |
33 |
Correct |
12 ms |
23952 KB |
Output is correct |
34 |
Correct |
11 ms |
23900 KB |
Output is correct |
35 |
Correct |
10 ms |
23900 KB |
Output is correct |
36 |
Correct |
12 ms |
23928 KB |
Output is correct |
37 |
Correct |
10 ms |
23896 KB |
Output is correct |
38 |
Correct |
15 ms |
23896 KB |
Output is correct |
39 |
Incorrect |
11 ms |
23896 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
10 ms |
23900 KB |
Output is correct |
3 |
Correct |
13 ms |
23900 KB |
Output is correct |
4 |
Correct |
13 ms |
23908 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
11 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23700 KB |
Output is correct |
8 |
Correct |
10 ms |
23896 KB |
Output is correct |
9 |
Correct |
11 ms |
23900 KB |
Output is correct |
10 |
Correct |
12 ms |
23896 KB |
Output is correct |
11 |
Correct |
11 ms |
23908 KB |
Output is correct |
12 |
Correct |
10 ms |
23896 KB |
Output is correct |
13 |
Correct |
10 ms |
23900 KB |
Output is correct |
14 |
Correct |
13 ms |
23948 KB |
Output is correct |
15 |
Correct |
10 ms |
23900 KB |
Output is correct |
16 |
Correct |
11 ms |
23896 KB |
Output is correct |
17 |
Correct |
14 ms |
23900 KB |
Output is correct |
18 |
Correct |
14 ms |
24004 KB |
Output is correct |
19 |
Correct |
11 ms |
23896 KB |
Output is correct |
20 |
Correct |
10 ms |
23900 KB |
Output is correct |
21 |
Correct |
10 ms |
23896 KB |
Output is correct |
22 |
Correct |
10 ms |
23900 KB |
Output is correct |
23 |
Correct |
10 ms |
23904 KB |
Output is correct |
24 |
Correct |
23 ms |
28368 KB |
Output is correct |
25 |
Correct |
31 ms |
28248 KB |
Output is correct |
26 |
Correct |
26 ms |
28300 KB |
Output is correct |
27 |
Correct |
10 ms |
23900 KB |
Output is correct |
28 |
Correct |
10 ms |
23896 KB |
Output is correct |
29 |
Correct |
9 ms |
23840 KB |
Output is correct |
30 |
Correct |
11 ms |
23900 KB |
Output is correct |
31 |
Correct |
10 ms |
23776 KB |
Output is correct |
32 |
Correct |
10 ms |
23952 KB |
Output is correct |
33 |
Correct |
10 ms |
23900 KB |
Output is correct |
34 |
Correct |
10 ms |
23836 KB |
Output is correct |
35 |
Correct |
10 ms |
23928 KB |
Output is correct |
36 |
Correct |
12 ms |
23952 KB |
Output is correct |
37 |
Correct |
11 ms |
23900 KB |
Output is correct |
38 |
Correct |
10 ms |
23900 KB |
Output is correct |
39 |
Correct |
12 ms |
23928 KB |
Output is correct |
40 |
Correct |
10 ms |
23896 KB |
Output is correct |
41 |
Correct |
15 ms |
23896 KB |
Output is correct |
42 |
Incorrect |
11 ms |
23896 KB |
Output isn't correct |
43 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
10 ms |
23900 KB |
Output is correct |
3 |
Correct |
13 ms |
23900 KB |
Output is correct |
4 |
Correct |
13 ms |
23908 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
11 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23700 KB |
Output is correct |
8 |
Correct |
10 ms |
23896 KB |
Output is correct |
9 |
Correct |
11 ms |
23900 KB |
Output is correct |
10 |
Correct |
12 ms |
23896 KB |
Output is correct |
11 |
Correct |
11 ms |
23908 KB |
Output is correct |
12 |
Correct |
10 ms |
23896 KB |
Output is correct |
13 |
Correct |
10 ms |
23900 KB |
Output is correct |
14 |
Correct |
13 ms |
23948 KB |
Output is correct |
15 |
Correct |
10 ms |
23900 KB |
Output is correct |
16 |
Correct |
11 ms |
23896 KB |
Output is correct |
17 |
Correct |
14 ms |
23900 KB |
Output is correct |
18 |
Correct |
14 ms |
24004 KB |
Output is correct |
19 |
Correct |
11 ms |
23896 KB |
Output is correct |
20 |
Correct |
10 ms |
23900 KB |
Output is correct |
21 |
Correct |
10 ms |
23896 KB |
Output is correct |
22 |
Correct |
10 ms |
23900 KB |
Output is correct |
23 |
Correct |
10 ms |
23904 KB |
Output is correct |
24 |
Correct |
23 ms |
28368 KB |
Output is correct |
25 |
Correct |
31 ms |
28248 KB |
Output is correct |
26 |
Correct |
26 ms |
28300 KB |
Output is correct |
27 |
Correct |
15 ms |
24060 KB |
Output is correct |
28 |
Correct |
14 ms |
24048 KB |
Output is correct |
29 |
Correct |
11 ms |
24156 KB |
Output is correct |
30 |
Correct |
12 ms |
24124 KB |
Output is correct |
31 |
Correct |
11 ms |
24408 KB |
Output is correct |
32 |
Correct |
11 ms |
24140 KB |
Output is correct |
33 |
Correct |
44 ms |
25176 KB |
Output is correct |
34 |
Correct |
42 ms |
25180 KB |
Output is correct |
35 |
Correct |
40 ms |
25432 KB |
Output is correct |
36 |
Correct |
41 ms |
25176 KB |
Output is correct |
37 |
Correct |
42 ms |
25284 KB |
Output is correct |
38 |
Correct |
58 ms |
25180 KB |
Output is correct |
39 |
Correct |
26 ms |
28764 KB |
Output is correct |
40 |
Correct |
25 ms |
28764 KB |
Output is correct |
41 |
Correct |
29 ms |
28756 KB |
Output is correct |
42 |
Correct |
10 ms |
23900 KB |
Output is correct |
43 |
Correct |
10 ms |
23896 KB |
Output is correct |
44 |
Correct |
9 ms |
23840 KB |
Output is correct |
45 |
Correct |
11 ms |
23900 KB |
Output is correct |
46 |
Correct |
10 ms |
23776 KB |
Output is correct |
47 |
Correct |
10 ms |
23952 KB |
Output is correct |
48 |
Correct |
10 ms |
23900 KB |
Output is correct |
49 |
Correct |
10 ms |
23836 KB |
Output is correct |
50 |
Correct |
10 ms |
23928 KB |
Output is correct |
51 |
Correct |
12 ms |
23952 KB |
Output is correct |
52 |
Correct |
11 ms |
23900 KB |
Output is correct |
53 |
Correct |
10 ms |
23900 KB |
Output is correct |
54 |
Correct |
12 ms |
23928 KB |
Output is correct |
55 |
Correct |
10 ms |
23896 KB |
Output is correct |
56 |
Correct |
15 ms |
23896 KB |
Output is correct |
57 |
Incorrect |
11 ms |
23896 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
10 ms |
23900 KB |
Output is correct |
3 |
Correct |
13 ms |
23900 KB |
Output is correct |
4 |
Correct |
13 ms |
23908 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
11 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23700 KB |
Output is correct |
8 |
Correct |
10 ms |
23896 KB |
Output is correct |
9 |
Correct |
11 ms |
23900 KB |
Output is correct |
10 |
Correct |
12 ms |
23896 KB |
Output is correct |
11 |
Correct |
11 ms |
23908 KB |
Output is correct |
12 |
Correct |
10 ms |
23896 KB |
Output is correct |
13 |
Correct |
10 ms |
23900 KB |
Output is correct |
14 |
Correct |
13 ms |
23948 KB |
Output is correct |
15 |
Correct |
10 ms |
23900 KB |
Output is correct |
16 |
Correct |
11 ms |
23896 KB |
Output is correct |
17 |
Correct |
14 ms |
23900 KB |
Output is correct |
18 |
Correct |
14 ms |
24004 KB |
Output is correct |
19 |
Correct |
11 ms |
23896 KB |
Output is correct |
20 |
Correct |
10 ms |
23900 KB |
Output is correct |
21 |
Correct |
10 ms |
23896 KB |
Output is correct |
22 |
Correct |
10 ms |
23900 KB |
Output is correct |
23 |
Correct |
10 ms |
23904 KB |
Output is correct |
24 |
Correct |
23 ms |
28368 KB |
Output is correct |
25 |
Correct |
31 ms |
28248 KB |
Output is correct |
26 |
Correct |
26 ms |
28300 KB |
Output is correct |
27 |
Correct |
15 ms |
24060 KB |
Output is correct |
28 |
Correct |
14 ms |
24048 KB |
Output is correct |
29 |
Correct |
11 ms |
24156 KB |
Output is correct |
30 |
Correct |
12 ms |
24124 KB |
Output is correct |
31 |
Correct |
11 ms |
24408 KB |
Output is correct |
32 |
Correct |
11 ms |
24140 KB |
Output is correct |
33 |
Correct |
44 ms |
25176 KB |
Output is correct |
34 |
Correct |
42 ms |
25180 KB |
Output is correct |
35 |
Correct |
40 ms |
25432 KB |
Output is correct |
36 |
Correct |
41 ms |
25176 KB |
Output is correct |
37 |
Correct |
42 ms |
25284 KB |
Output is correct |
38 |
Correct |
58 ms |
25180 KB |
Output is correct |
39 |
Correct |
26 ms |
28764 KB |
Output is correct |
40 |
Correct |
25 ms |
28764 KB |
Output is correct |
41 |
Correct |
29 ms |
28756 KB |
Output is correct |
42 |
Correct |
16 ms |
25176 KB |
Output is correct |
43 |
Correct |
13 ms |
24668 KB |
Output is correct |
44 |
Correct |
18 ms |
25232 KB |
Output is correct |
45 |
Correct |
14 ms |
24664 KB |
Output is correct |
46 |
Correct |
14 ms |
24668 KB |
Output is correct |
47 |
Correct |
18 ms |
25300 KB |
Output is correct |
48 |
Correct |
1350 ms |
34900 KB |
Output is correct |
49 |
Correct |
601 ms |
30036 KB |
Output is correct |
50 |
Correct |
316 ms |
32600 KB |
Output is correct |
51 |
Correct |
33 ms |
33052 KB |
Output is correct |
52 |
Correct |
35 ms |
32596 KB |
Output is correct |
53 |
Correct |
30 ms |
30288 KB |
Output is correct |
54 |
Correct |
15 ms |
25180 KB |
Output is correct |
55 |
Correct |
17 ms |
25176 KB |
Output is correct |
56 |
Correct |
17 ms |
25176 KB |
Output is correct |
57 |
Correct |
18 ms |
25180 KB |
Output is correct |
58 |
Correct |
17 ms |
25288 KB |
Output is correct |
59 |
Correct |
16 ms |
25180 KB |
Output is correct |
60 |
Execution timed out |
1528 ms |
35664 KB |
Time limit exceeded |
61 |
Halted |
0 ms |
0 KB |
- |