#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;
}
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 |
11 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
23728 KB |
Output is correct |
3 |
Correct |
10 ms |
23900 KB |
Output is correct |
4 |
Correct |
12 ms |
23848 KB |
Output is correct |
5 |
Correct |
12 ms |
23900 KB |
Output is correct |
6 |
Correct |
13 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23732 KB |
Output is correct |
8 |
Correct |
10 ms |
23900 KB |
Output is correct |
9 |
Correct |
11 ms |
23900 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
11 |
Correct |
11 ms |
23900 KB |
Output is correct |
12 |
Correct |
10 ms |
23740 KB |
Output is correct |
13 |
Correct |
11 ms |
23768 KB |
Output is correct |
14 |
Correct |
11 ms |
23932 KB |
Output is correct |
15 |
Correct |
11 ms |
23900 KB |
Output is correct |
16 |
Correct |
14 ms |
23900 KB |
Output is correct |
17 |
Correct |
15 ms |
23900 KB |
Output is correct |
18 |
Correct |
11 ms |
24000 KB |
Output is correct |
19 |
Correct |
17 ms |
23900 KB |
Output is correct |
20 |
Correct |
11 ms |
23900 KB |
Output is correct |
21 |
Correct |
11 ms |
23904 KB |
Output is correct |
22 |
Correct |
24 ms |
28348 KB |
Output is correct |
23 |
Correct |
24 ms |
28252 KB |
Output is correct |
24 |
Correct |
26 ms |
28456 KB |
Output is correct |
25 |
Correct |
14 ms |
24156 KB |
Output is correct |
26 |
Correct |
11 ms |
24156 KB |
Output is correct |
27 |
Correct |
11 ms |
24156 KB |
Output is correct |
28 |
Correct |
12 ms |
24048 KB |
Output is correct |
29 |
Correct |
12 ms |
24156 KB |
Output is correct |
30 |
Correct |
15 ms |
24156 KB |
Output is correct |
31 |
Correct |
40 ms |
25120 KB |
Output is correct |
32 |
Correct |
40 ms |
25180 KB |
Output is correct |
33 |
Correct |
41 ms |
25180 KB |
Output is correct |
34 |
Correct |
40 ms |
25320 KB |
Output is correct |
35 |
Correct |
44 ms |
25292 KB |
Output is correct |
36 |
Correct |
40 ms |
25176 KB |
Output is correct |
37 |
Correct |
28 ms |
28764 KB |
Output is correct |
38 |
Correct |
29 ms |
28764 KB |
Output is correct |
39 |
Correct |
28 ms |
28856 KB |
Output is correct |
40 |
Correct |
15 ms |
25180 KB |
Output is correct |
41 |
Correct |
14 ms |
24668 KB |
Output is correct |
42 |
Correct |
18 ms |
25180 KB |
Output is correct |
43 |
Correct |
20 ms |
24664 KB |
Output is correct |
44 |
Correct |
15 ms |
24668 KB |
Output is correct |
45 |
Correct |
17 ms |
25180 KB |
Output is correct |
46 |
Correct |
1333 ms |
34900 KB |
Output is correct |
47 |
Correct |
567 ms |
30036 KB |
Output is correct |
48 |
Correct |
388 ms |
32852 KB |
Output is correct |
49 |
Correct |
34 ms |
32920 KB |
Output is correct |
50 |
Correct |
34 ms |
32604 KB |
Output is correct |
51 |
Correct |
37 ms |
30292 KB |
Output is correct |
52 |
Correct |
19 ms |
25180 KB |
Output is correct |
53 |
Correct |
16 ms |
25180 KB |
Output is correct |
54 |
Correct |
22 ms |
25180 KB |
Output is correct |
55 |
Correct |
17 ms |
25180 KB |
Output is correct |
56 |
Correct |
23 ms |
25284 KB |
Output is correct |
57 |
Correct |
20 ms |
25216 KB |
Output is correct |
58 |
Execution timed out |
1578 ms |
35892 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
23728 KB |
Output is correct |
3 |
Correct |
10 ms |
23900 KB |
Output is correct |
4 |
Correct |
12 ms |
23848 KB |
Output is correct |
5 |
Correct |
12 ms |
23900 KB |
Output is correct |
6 |
Correct |
13 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23732 KB |
Output is correct |
8 |
Correct |
10 ms |
23900 KB |
Output is correct |
9 |
Correct |
11 ms |
23900 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
11 |
Correct |
11 ms |
23900 KB |
Output is correct |
12 |
Correct |
10 ms |
23740 KB |
Output is correct |
13 |
Correct |
11 ms |
23768 KB |
Output is correct |
14 |
Correct |
11 ms |
23932 KB |
Output is correct |
15 |
Correct |
11 ms |
23900 KB |
Output is correct |
16 |
Correct |
14 ms |
23900 KB |
Output is correct |
17 |
Correct |
15 ms |
23900 KB |
Output is correct |
18 |
Correct |
11 ms |
24000 KB |
Output is correct |
19 |
Correct |
17 ms |
23900 KB |
Output is correct |
20 |
Correct |
11 ms |
23900 KB |
Output is correct |
21 |
Correct |
11 ms |
23904 KB |
Output is correct |
22 |
Correct |
10 ms |
23900 KB |
Output is correct |
23 |
Correct |
16 ms |
23924 KB |
Output is correct |
24 |
Correct |
11 ms |
23900 KB |
Output is correct |
25 |
Correct |
10 ms |
23924 KB |
Output is correct |
26 |
Correct |
10 ms |
23800 KB |
Output is correct |
27 |
Correct |
10 ms |
23900 KB |
Output is correct |
28 |
Correct |
12 ms |
23744 KB |
Output is correct |
29 |
Correct |
10 ms |
23952 KB |
Output is correct |
30 |
Correct |
10 ms |
23900 KB |
Output is correct |
31 |
Correct |
12 ms |
23900 KB |
Output is correct |
32 |
Correct |
12 ms |
23900 KB |
Output is correct |
33 |
Correct |
11 ms |
23896 KB |
Output is correct |
34 |
Correct |
14 ms |
23900 KB |
Output is correct |
35 |
Correct |
11 ms |
23924 KB |
Output is correct |
36 |
Correct |
10 ms |
23900 KB |
Output is correct |
37 |
Correct |
11 ms |
23900 KB |
Output is correct |
38 |
Correct |
15 ms |
23920 KB |
Output is correct |
39 |
Incorrect |
10 ms |
23764 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
16 ms |
23924 KB |
Output is correct |
3 |
Correct |
11 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23728 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
12 ms |
23848 KB |
Output is correct |
7 |
Correct |
12 ms |
23900 KB |
Output is correct |
8 |
Correct |
13 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23732 KB |
Output is correct |
10 |
Correct |
10 ms |
23900 KB |
Output is correct |
11 |
Correct |
11 ms |
23900 KB |
Output is correct |
12 |
Correct |
9 ms |
23900 KB |
Output is correct |
13 |
Correct |
11 ms |
23900 KB |
Output is correct |
14 |
Correct |
10 ms |
23740 KB |
Output is correct |
15 |
Correct |
11 ms |
23768 KB |
Output is correct |
16 |
Correct |
11 ms |
23932 KB |
Output is correct |
17 |
Correct |
11 ms |
23900 KB |
Output is correct |
18 |
Correct |
14 ms |
23900 KB |
Output is correct |
19 |
Correct |
15 ms |
23900 KB |
Output is correct |
20 |
Correct |
11 ms |
24000 KB |
Output is correct |
21 |
Correct |
17 ms |
23900 KB |
Output is correct |
22 |
Correct |
11 ms |
23900 KB |
Output is correct |
23 |
Correct |
11 ms |
23904 KB |
Output is correct |
24 |
Correct |
24 ms |
28348 KB |
Output is correct |
25 |
Correct |
24 ms |
28252 KB |
Output is correct |
26 |
Correct |
26 ms |
28456 KB |
Output is correct |
27 |
Correct |
11 ms |
23900 KB |
Output is correct |
28 |
Correct |
10 ms |
23924 KB |
Output is correct |
29 |
Correct |
10 ms |
23800 KB |
Output is correct |
30 |
Correct |
10 ms |
23900 KB |
Output is correct |
31 |
Correct |
12 ms |
23744 KB |
Output is correct |
32 |
Correct |
10 ms |
23952 KB |
Output is correct |
33 |
Correct |
10 ms |
23900 KB |
Output is correct |
34 |
Correct |
12 ms |
23900 KB |
Output is correct |
35 |
Correct |
12 ms |
23900 KB |
Output is correct |
36 |
Correct |
11 ms |
23896 KB |
Output is correct |
37 |
Correct |
14 ms |
23900 KB |
Output is correct |
38 |
Correct |
11 ms |
23924 KB |
Output is correct |
39 |
Correct |
10 ms |
23900 KB |
Output is correct |
40 |
Correct |
11 ms |
23900 KB |
Output is correct |
41 |
Correct |
15 ms |
23920 KB |
Output is correct |
42 |
Incorrect |
10 ms |
23764 KB |
Output isn't correct |
43 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
16 ms |
23924 KB |
Output is correct |
3 |
Correct |
11 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23728 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
12 ms |
23848 KB |
Output is correct |
7 |
Correct |
12 ms |
23900 KB |
Output is correct |
8 |
Correct |
13 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23732 KB |
Output is correct |
10 |
Correct |
10 ms |
23900 KB |
Output is correct |
11 |
Correct |
11 ms |
23900 KB |
Output is correct |
12 |
Correct |
9 ms |
23900 KB |
Output is correct |
13 |
Correct |
11 ms |
23900 KB |
Output is correct |
14 |
Correct |
10 ms |
23740 KB |
Output is correct |
15 |
Correct |
11 ms |
23768 KB |
Output is correct |
16 |
Correct |
11 ms |
23932 KB |
Output is correct |
17 |
Correct |
11 ms |
23900 KB |
Output is correct |
18 |
Correct |
14 ms |
23900 KB |
Output is correct |
19 |
Correct |
15 ms |
23900 KB |
Output is correct |
20 |
Correct |
11 ms |
24000 KB |
Output is correct |
21 |
Correct |
17 ms |
23900 KB |
Output is correct |
22 |
Correct |
11 ms |
23900 KB |
Output is correct |
23 |
Correct |
11 ms |
23904 KB |
Output is correct |
24 |
Correct |
24 ms |
28348 KB |
Output is correct |
25 |
Correct |
24 ms |
28252 KB |
Output is correct |
26 |
Correct |
26 ms |
28456 KB |
Output is correct |
27 |
Correct |
14 ms |
24156 KB |
Output is correct |
28 |
Correct |
11 ms |
24156 KB |
Output is correct |
29 |
Correct |
11 ms |
24156 KB |
Output is correct |
30 |
Correct |
12 ms |
24048 KB |
Output is correct |
31 |
Correct |
12 ms |
24156 KB |
Output is correct |
32 |
Correct |
15 ms |
24156 KB |
Output is correct |
33 |
Correct |
40 ms |
25120 KB |
Output is correct |
34 |
Correct |
40 ms |
25180 KB |
Output is correct |
35 |
Correct |
41 ms |
25180 KB |
Output is correct |
36 |
Correct |
40 ms |
25320 KB |
Output is correct |
37 |
Correct |
44 ms |
25292 KB |
Output is correct |
38 |
Correct |
40 ms |
25176 KB |
Output is correct |
39 |
Correct |
28 ms |
28764 KB |
Output is correct |
40 |
Correct |
29 ms |
28764 KB |
Output is correct |
41 |
Correct |
28 ms |
28856 KB |
Output is correct |
42 |
Correct |
11 ms |
23900 KB |
Output is correct |
43 |
Correct |
10 ms |
23924 KB |
Output is correct |
44 |
Correct |
10 ms |
23800 KB |
Output is correct |
45 |
Correct |
10 ms |
23900 KB |
Output is correct |
46 |
Correct |
12 ms |
23744 KB |
Output is correct |
47 |
Correct |
10 ms |
23952 KB |
Output is correct |
48 |
Correct |
10 ms |
23900 KB |
Output is correct |
49 |
Correct |
12 ms |
23900 KB |
Output is correct |
50 |
Correct |
12 ms |
23900 KB |
Output is correct |
51 |
Correct |
11 ms |
23896 KB |
Output is correct |
52 |
Correct |
14 ms |
23900 KB |
Output is correct |
53 |
Correct |
11 ms |
23924 KB |
Output is correct |
54 |
Correct |
10 ms |
23900 KB |
Output is correct |
55 |
Correct |
11 ms |
23900 KB |
Output is correct |
56 |
Correct |
15 ms |
23920 KB |
Output is correct |
57 |
Incorrect |
10 ms |
23764 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
16 ms |
23924 KB |
Output is correct |
3 |
Correct |
11 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23728 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
12 ms |
23848 KB |
Output is correct |
7 |
Correct |
12 ms |
23900 KB |
Output is correct |
8 |
Correct |
13 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23732 KB |
Output is correct |
10 |
Correct |
10 ms |
23900 KB |
Output is correct |
11 |
Correct |
11 ms |
23900 KB |
Output is correct |
12 |
Correct |
9 ms |
23900 KB |
Output is correct |
13 |
Correct |
11 ms |
23900 KB |
Output is correct |
14 |
Correct |
10 ms |
23740 KB |
Output is correct |
15 |
Correct |
11 ms |
23768 KB |
Output is correct |
16 |
Correct |
11 ms |
23932 KB |
Output is correct |
17 |
Correct |
11 ms |
23900 KB |
Output is correct |
18 |
Correct |
14 ms |
23900 KB |
Output is correct |
19 |
Correct |
15 ms |
23900 KB |
Output is correct |
20 |
Correct |
11 ms |
24000 KB |
Output is correct |
21 |
Correct |
17 ms |
23900 KB |
Output is correct |
22 |
Correct |
11 ms |
23900 KB |
Output is correct |
23 |
Correct |
11 ms |
23904 KB |
Output is correct |
24 |
Correct |
24 ms |
28348 KB |
Output is correct |
25 |
Correct |
24 ms |
28252 KB |
Output is correct |
26 |
Correct |
26 ms |
28456 KB |
Output is correct |
27 |
Correct |
14 ms |
24156 KB |
Output is correct |
28 |
Correct |
11 ms |
24156 KB |
Output is correct |
29 |
Correct |
11 ms |
24156 KB |
Output is correct |
30 |
Correct |
12 ms |
24048 KB |
Output is correct |
31 |
Correct |
12 ms |
24156 KB |
Output is correct |
32 |
Correct |
15 ms |
24156 KB |
Output is correct |
33 |
Correct |
40 ms |
25120 KB |
Output is correct |
34 |
Correct |
40 ms |
25180 KB |
Output is correct |
35 |
Correct |
41 ms |
25180 KB |
Output is correct |
36 |
Correct |
40 ms |
25320 KB |
Output is correct |
37 |
Correct |
44 ms |
25292 KB |
Output is correct |
38 |
Correct |
40 ms |
25176 KB |
Output is correct |
39 |
Correct |
28 ms |
28764 KB |
Output is correct |
40 |
Correct |
29 ms |
28764 KB |
Output is correct |
41 |
Correct |
28 ms |
28856 KB |
Output is correct |
42 |
Correct |
15 ms |
25180 KB |
Output is correct |
43 |
Correct |
14 ms |
24668 KB |
Output is correct |
44 |
Correct |
18 ms |
25180 KB |
Output is correct |
45 |
Correct |
20 ms |
24664 KB |
Output is correct |
46 |
Correct |
15 ms |
24668 KB |
Output is correct |
47 |
Correct |
17 ms |
25180 KB |
Output is correct |
48 |
Correct |
1333 ms |
34900 KB |
Output is correct |
49 |
Correct |
567 ms |
30036 KB |
Output is correct |
50 |
Correct |
388 ms |
32852 KB |
Output is correct |
51 |
Correct |
34 ms |
32920 KB |
Output is correct |
52 |
Correct |
34 ms |
32604 KB |
Output is correct |
53 |
Correct |
37 ms |
30292 KB |
Output is correct |
54 |
Correct |
19 ms |
25180 KB |
Output is correct |
55 |
Correct |
16 ms |
25180 KB |
Output is correct |
56 |
Correct |
22 ms |
25180 KB |
Output is correct |
57 |
Correct |
17 ms |
25180 KB |
Output is correct |
58 |
Correct |
23 ms |
25284 KB |
Output is correct |
59 |
Correct |
20 ms |
25216 KB |
Output is correct |
60 |
Execution timed out |
1578 ms |
35892 KB |
Time limit exceeded |
61 |
Halted |
0 ms |
0 KB |
- |