#include "paint.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int inf = 2e4+9,MX = 1e9+9;
int n,m,k;
int a[inf];
vector<int> Cont[inf];
int LCS[inf][2009],dp[inf];
bool valid[inf],like[2009][inf];
unordered_map<int,int> mp[inf];
int solve(int i,int j){
if( !(j>=1 && j<=m && i>=1 && i<=n) )
return 0;
int &ret = LCS[i][j];
if(ret != -1)
return ret;
ret = 0;
int idx=0;
/*if(!Cont[j].empty() ){
idx = lower_bound(Cont[j].begin(),Cont[j].end(),a[i])-Cont[j].begin();
if(idx < Cont[j].size() && Cont[j][idx] == a[i])
ret = 1 + solve(i+1,j+1);
}*/
if(like[j][a[i]])
ret = 1 + solve(i+1,j+1);
return ret;
}
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=1;i<=n;i++)
a[i] = C[i-1]+1;
for(int i=1;i<=m;i++){
for(auto o:B[i-1]){
like[i][o+1] = 1;
Cont[i].push_back(o+1);
}
}
for(int i=1;i<=m;i++)
if(!Cont[i].empty())
sort(Cont[i].begin(),Cont[i].end());
memset(LCS,-1,sizeof(LCS));
for(int y=1;y <= n-m+1;y++){
for(int x = 1;x <= m;x++){
int len1 = m-x+1,i1 = y,j1 = x,tmp1;
tmp1 = solve(i1,j1);
int len2 = x-1,i2 = y+len1,j2 = 1,tmp2 = 0;
if(len2)
tmp2 = solve(i2,j2);
valid[y] |= (tmp1 >= len1 && tmp2 >= len2);
}
}
for(int i=1;i<=n;i++)
dp[i] = MX;
dp[n-m+1] = (valid[n-m+1]?1:MX);
for(int i=n-m;i>=1;i--)
for(int j=i+1;j<=i+m && valid[i];j++)
dp[i] = min(dp[i],dp[j] + 1);
return ( (dp[1] == MX)?-1:dp[1]);
}
Compilation message
paint.cpp: In function 'int solve(int, int)':
paint.cpp:22:9: warning: unused variable 'idx' [-Wunused-variable]
22 | int idx=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
159224 KB |
Output is correct |
2 |
Correct |
89 ms |
159224 KB |
Output is correct |
3 |
Correct |
87 ms |
159224 KB |
Output is correct |
4 |
Correct |
88 ms |
159224 KB |
Output is correct |
5 |
Correct |
91 ms |
159224 KB |
Output is correct |
6 |
Correct |
89 ms |
159256 KB |
Output is correct |
7 |
Correct |
89 ms |
159356 KB |
Output is correct |
8 |
Correct |
88 ms |
159228 KB |
Output is correct |
9 |
Correct |
88 ms |
159224 KB |
Output is correct |
10 |
Correct |
90 ms |
159224 KB |
Output is correct |
11 |
Correct |
90 ms |
159224 KB |
Output is correct |
12 |
Correct |
88 ms |
159224 KB |
Output is correct |
13 |
Correct |
90 ms |
160888 KB |
Output is correct |
14 |
Correct |
92 ms |
161016 KB |
Output is correct |
15 |
Correct |
91 ms |
160888 KB |
Output is correct |
16 |
Correct |
93 ms |
160760 KB |
Output is correct |
17 |
Correct |
90 ms |
160888 KB |
Output is correct |
18 |
Correct |
91 ms |
160888 KB |
Output is correct |
19 |
Correct |
92 ms |
161788 KB |
Output is correct |
20 |
Correct |
93 ms |
161784 KB |
Output is correct |
21 |
Correct |
93 ms |
161784 KB |
Output is correct |
22 |
Correct |
109 ms |
164600 KB |
Output is correct |
23 |
Correct |
110 ms |
164592 KB |
Output is correct |
24 |
Correct |
114 ms |
164520 KB |
Output is correct |
25 |
Correct |
94 ms |
159480 KB |
Output is correct |
26 |
Correct |
98 ms |
159480 KB |
Output is correct |
27 |
Correct |
98 ms |
159480 KB |
Output is correct |
28 |
Correct |
94 ms |
159480 KB |
Output is correct |
29 |
Correct |
95 ms |
159612 KB |
Output is correct |
30 |
Correct |
97 ms |
159608 KB |
Output is correct |
31 |
Execution timed out |
1540 ms |
194428 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
159224 KB |
Output is correct |
2 |
Correct |
89 ms |
159352 KB |
Output is correct |
3 |
Correct |
89 ms |
159224 KB |
Output is correct |
4 |
Correct |
89 ms |
159224 KB |
Output is correct |
5 |
Correct |
87 ms |
159224 KB |
Output is correct |
6 |
Correct |
88 ms |
159224 KB |
Output is correct |
7 |
Correct |
91 ms |
159224 KB |
Output is correct |
8 |
Correct |
89 ms |
159256 KB |
Output is correct |
9 |
Correct |
89 ms |
159356 KB |
Output is correct |
10 |
Correct |
88 ms |
159228 KB |
Output is correct |
11 |
Correct |
88 ms |
159224 KB |
Output is correct |
12 |
Correct |
90 ms |
159224 KB |
Output is correct |
13 |
Correct |
90 ms |
159224 KB |
Output is correct |
14 |
Correct |
88 ms |
159224 KB |
Output is correct |
15 |
Correct |
90 ms |
160888 KB |
Output is correct |
16 |
Correct |
92 ms |
161016 KB |
Output is correct |
17 |
Correct |
91 ms |
160888 KB |
Output is correct |
18 |
Correct |
93 ms |
160760 KB |
Output is correct |
19 |
Correct |
90 ms |
160888 KB |
Output is correct |
20 |
Correct |
91 ms |
160888 KB |
Output is correct |
21 |
Correct |
92 ms |
161788 KB |
Output is correct |
22 |
Correct |
93 ms |
161784 KB |
Output is correct |
23 |
Correct |
93 ms |
161784 KB |
Output is correct |
24 |
Correct |
88 ms |
159252 KB |
Output is correct |
25 |
Correct |
92 ms |
159224 KB |
Output is correct |
26 |
Correct |
92 ms |
159352 KB |
Output is correct |
27 |
Correct |
88 ms |
159224 KB |
Output is correct |
28 |
Correct |
90 ms |
159320 KB |
Output is correct |
29 |
Correct |
89 ms |
159336 KB |
Output is correct |
30 |
Correct |
90 ms |
159352 KB |
Output is correct |
31 |
Correct |
99 ms |
159224 KB |
Output is correct |
32 |
Correct |
96 ms |
159352 KB |
Output is correct |
33 |
Correct |
90 ms |
160504 KB |
Output is correct |
34 |
Correct |
88 ms |
160632 KB |
Output is correct |
35 |
Correct |
89 ms |
160120 KB |
Output is correct |
36 |
Correct |
86 ms |
160504 KB |
Output is correct |
37 |
Correct |
88 ms |
160376 KB |
Output is correct |
38 |
Correct |
86 ms |
159352 KB |
Output is correct |
39 |
Correct |
88 ms |
159224 KB |
Output is correct |
40 |
Correct |
91 ms |
161528 KB |
Output is correct |
41 |
Correct |
94 ms |
159864 KB |
Output is correct |
42 |
Correct |
91 ms |
160632 KB |
Output is correct |
43 |
Correct |
95 ms |
160104 KB |
Output is correct |
44 |
Correct |
94 ms |
159224 KB |
Output is correct |
45 |
Correct |
96 ms |
159384 KB |
Output is correct |
46 |
Correct |
89 ms |
159352 KB |
Output is correct |
47 |
Correct |
90 ms |
159480 KB |
Output is correct |
48 |
Correct |
96 ms |
159480 KB |
Output is correct |
49 |
Correct |
88 ms |
159480 KB |
Output is correct |
50 |
Correct |
89 ms |
160888 KB |
Output is correct |
51 |
Correct |
87 ms |
160888 KB |
Output is correct |
52 |
Correct |
84 ms |
160888 KB |
Output is correct |
53 |
Correct |
87 ms |
160888 KB |
Output is correct |
54 |
Correct |
85 ms |
160800 KB |
Output is correct |
55 |
Correct |
84 ms |
160888 KB |
Output is correct |
56 |
Correct |
88 ms |
161784 KB |
Output is correct |
57 |
Correct |
83 ms |
160232 KB |
Output is correct |
58 |
Correct |
87 ms |
161656 KB |
Output is correct |
59 |
Correct |
85 ms |
160120 KB |
Output is correct |
60 |
Correct |
87 ms |
161912 KB |
Output is correct |
61 |
Correct |
90 ms |
160120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
159224 KB |
Output is correct |
2 |
Correct |
89 ms |
159352 KB |
Output is correct |
3 |
Correct |
89 ms |
159224 KB |
Output is correct |
4 |
Correct |
89 ms |
159224 KB |
Output is correct |
5 |
Correct |
87 ms |
159224 KB |
Output is correct |
6 |
Correct |
88 ms |
159224 KB |
Output is correct |
7 |
Correct |
91 ms |
159224 KB |
Output is correct |
8 |
Correct |
89 ms |
159256 KB |
Output is correct |
9 |
Correct |
89 ms |
159356 KB |
Output is correct |
10 |
Correct |
88 ms |
159228 KB |
Output is correct |
11 |
Correct |
88 ms |
159224 KB |
Output is correct |
12 |
Correct |
90 ms |
159224 KB |
Output is correct |
13 |
Correct |
90 ms |
159224 KB |
Output is correct |
14 |
Correct |
88 ms |
159224 KB |
Output is correct |
15 |
Correct |
90 ms |
160888 KB |
Output is correct |
16 |
Correct |
92 ms |
161016 KB |
Output is correct |
17 |
Correct |
91 ms |
160888 KB |
Output is correct |
18 |
Correct |
93 ms |
160760 KB |
Output is correct |
19 |
Correct |
90 ms |
160888 KB |
Output is correct |
20 |
Correct |
91 ms |
160888 KB |
Output is correct |
21 |
Correct |
92 ms |
161788 KB |
Output is correct |
22 |
Correct |
93 ms |
161784 KB |
Output is correct |
23 |
Correct |
93 ms |
161784 KB |
Output is correct |
24 |
Correct |
109 ms |
164600 KB |
Output is correct |
25 |
Correct |
110 ms |
164592 KB |
Output is correct |
26 |
Correct |
114 ms |
164520 KB |
Output is correct |
27 |
Correct |
88 ms |
159252 KB |
Output is correct |
28 |
Correct |
92 ms |
159224 KB |
Output is correct |
29 |
Correct |
92 ms |
159352 KB |
Output is correct |
30 |
Correct |
88 ms |
159224 KB |
Output is correct |
31 |
Correct |
90 ms |
159320 KB |
Output is correct |
32 |
Correct |
89 ms |
159336 KB |
Output is correct |
33 |
Correct |
90 ms |
159352 KB |
Output is correct |
34 |
Correct |
99 ms |
159224 KB |
Output is correct |
35 |
Correct |
96 ms |
159352 KB |
Output is correct |
36 |
Correct |
90 ms |
160504 KB |
Output is correct |
37 |
Correct |
88 ms |
160632 KB |
Output is correct |
38 |
Correct |
89 ms |
160120 KB |
Output is correct |
39 |
Correct |
86 ms |
160504 KB |
Output is correct |
40 |
Correct |
88 ms |
160376 KB |
Output is correct |
41 |
Correct |
86 ms |
159352 KB |
Output is correct |
42 |
Correct |
88 ms |
159224 KB |
Output is correct |
43 |
Correct |
91 ms |
161528 KB |
Output is correct |
44 |
Correct |
94 ms |
159864 KB |
Output is correct |
45 |
Correct |
91 ms |
160632 KB |
Output is correct |
46 |
Correct |
95 ms |
160104 KB |
Output is correct |
47 |
Correct |
94 ms |
159224 KB |
Output is correct |
48 |
Correct |
96 ms |
159384 KB |
Output is correct |
49 |
Correct |
89 ms |
159352 KB |
Output is correct |
50 |
Correct |
90 ms |
159480 KB |
Output is correct |
51 |
Correct |
96 ms |
159480 KB |
Output is correct |
52 |
Correct |
88 ms |
159480 KB |
Output is correct |
53 |
Correct |
89 ms |
160888 KB |
Output is correct |
54 |
Correct |
87 ms |
160888 KB |
Output is correct |
55 |
Correct |
84 ms |
160888 KB |
Output is correct |
56 |
Correct |
87 ms |
160888 KB |
Output is correct |
57 |
Correct |
85 ms |
160800 KB |
Output is correct |
58 |
Correct |
84 ms |
160888 KB |
Output is correct |
59 |
Correct |
88 ms |
161784 KB |
Output is correct |
60 |
Correct |
83 ms |
160232 KB |
Output is correct |
61 |
Correct |
87 ms |
161656 KB |
Output is correct |
62 |
Correct |
85 ms |
160120 KB |
Output is correct |
63 |
Correct |
87 ms |
161912 KB |
Output is correct |
64 |
Correct |
90 ms |
160120 KB |
Output is correct |
65 |
Correct |
89 ms |
159992 KB |
Output is correct |
66 |
Correct |
89 ms |
159356 KB |
Output is correct |
67 |
Correct |
90 ms |
159736 KB |
Output is correct |
68 |
Correct |
90 ms |
159480 KB |
Output is correct |
69 |
Correct |
88 ms |
159736 KB |
Output is correct |
70 |
Correct |
89 ms |
163064 KB |
Output is correct |
71 |
Correct |
87 ms |
162424 KB |
Output is correct |
72 |
Correct |
97 ms |
160888 KB |
Output is correct |
73 |
Correct |
85 ms |
159608 KB |
Output is correct |
74 |
Correct |
91 ms |
161528 KB |
Output is correct |
75 |
Correct |
88 ms |
163064 KB |
Output is correct |
76 |
Correct |
100 ms |
162936 KB |
Output is correct |
77 |
Correct |
104 ms |
161012 KB |
Output is correct |
78 |
Correct |
103 ms |
161784 KB |
Output is correct |
79 |
Correct |
88 ms |
160120 KB |
Output is correct |
80 |
Correct |
91 ms |
160120 KB |
Output is correct |
81 |
Correct |
90 ms |
159992 KB |
Output is correct |
82 |
Correct |
88 ms |
160120 KB |
Output is correct |
83 |
Correct |
89 ms |
160120 KB |
Output is correct |
84 |
Correct |
98 ms |
163452 KB |
Output is correct |
85 |
Correct |
94 ms |
163452 KB |
Output is correct |
86 |
Correct |
93 ms |
163448 KB |
Output is correct |
87 |
Correct |
88 ms |
163448 KB |
Output is correct |
88 |
Correct |
89 ms |
163448 KB |
Output is correct |
89 |
Correct |
88 ms |
163448 KB |
Output is correct |
90 |
Correct |
113 ms |
165240 KB |
Output is correct |
91 |
Correct |
108 ms |
165240 KB |
Output is correct |
92 |
Correct |
109 ms |
165240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
159224 KB |
Output is correct |
2 |
Correct |
89 ms |
159352 KB |
Output is correct |
3 |
Correct |
89 ms |
159224 KB |
Output is correct |
4 |
Correct |
89 ms |
159224 KB |
Output is correct |
5 |
Correct |
87 ms |
159224 KB |
Output is correct |
6 |
Correct |
88 ms |
159224 KB |
Output is correct |
7 |
Correct |
91 ms |
159224 KB |
Output is correct |
8 |
Correct |
89 ms |
159256 KB |
Output is correct |
9 |
Correct |
89 ms |
159356 KB |
Output is correct |
10 |
Correct |
88 ms |
159228 KB |
Output is correct |
11 |
Correct |
88 ms |
159224 KB |
Output is correct |
12 |
Correct |
90 ms |
159224 KB |
Output is correct |
13 |
Correct |
90 ms |
159224 KB |
Output is correct |
14 |
Correct |
88 ms |
159224 KB |
Output is correct |
15 |
Correct |
90 ms |
160888 KB |
Output is correct |
16 |
Correct |
92 ms |
161016 KB |
Output is correct |
17 |
Correct |
91 ms |
160888 KB |
Output is correct |
18 |
Correct |
93 ms |
160760 KB |
Output is correct |
19 |
Correct |
90 ms |
160888 KB |
Output is correct |
20 |
Correct |
91 ms |
160888 KB |
Output is correct |
21 |
Correct |
92 ms |
161788 KB |
Output is correct |
22 |
Correct |
93 ms |
161784 KB |
Output is correct |
23 |
Correct |
93 ms |
161784 KB |
Output is correct |
24 |
Correct |
109 ms |
164600 KB |
Output is correct |
25 |
Correct |
110 ms |
164592 KB |
Output is correct |
26 |
Correct |
114 ms |
164520 KB |
Output is correct |
27 |
Correct |
94 ms |
159480 KB |
Output is correct |
28 |
Correct |
98 ms |
159480 KB |
Output is correct |
29 |
Correct |
98 ms |
159480 KB |
Output is correct |
30 |
Correct |
94 ms |
159480 KB |
Output is correct |
31 |
Correct |
95 ms |
159612 KB |
Output is correct |
32 |
Correct |
97 ms |
159608 KB |
Output is correct |
33 |
Execution timed out |
1540 ms |
194428 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
159224 KB |
Output is correct |
2 |
Correct |
89 ms |
159352 KB |
Output is correct |
3 |
Correct |
89 ms |
159224 KB |
Output is correct |
4 |
Correct |
89 ms |
159224 KB |
Output is correct |
5 |
Correct |
87 ms |
159224 KB |
Output is correct |
6 |
Correct |
88 ms |
159224 KB |
Output is correct |
7 |
Correct |
91 ms |
159224 KB |
Output is correct |
8 |
Correct |
89 ms |
159256 KB |
Output is correct |
9 |
Correct |
89 ms |
159356 KB |
Output is correct |
10 |
Correct |
88 ms |
159228 KB |
Output is correct |
11 |
Correct |
88 ms |
159224 KB |
Output is correct |
12 |
Correct |
90 ms |
159224 KB |
Output is correct |
13 |
Correct |
90 ms |
159224 KB |
Output is correct |
14 |
Correct |
88 ms |
159224 KB |
Output is correct |
15 |
Correct |
90 ms |
160888 KB |
Output is correct |
16 |
Correct |
92 ms |
161016 KB |
Output is correct |
17 |
Correct |
91 ms |
160888 KB |
Output is correct |
18 |
Correct |
93 ms |
160760 KB |
Output is correct |
19 |
Correct |
90 ms |
160888 KB |
Output is correct |
20 |
Correct |
91 ms |
160888 KB |
Output is correct |
21 |
Correct |
92 ms |
161788 KB |
Output is correct |
22 |
Correct |
93 ms |
161784 KB |
Output is correct |
23 |
Correct |
93 ms |
161784 KB |
Output is correct |
24 |
Correct |
109 ms |
164600 KB |
Output is correct |
25 |
Correct |
110 ms |
164592 KB |
Output is correct |
26 |
Correct |
114 ms |
164520 KB |
Output is correct |
27 |
Correct |
94 ms |
159480 KB |
Output is correct |
28 |
Correct |
98 ms |
159480 KB |
Output is correct |
29 |
Correct |
98 ms |
159480 KB |
Output is correct |
30 |
Correct |
94 ms |
159480 KB |
Output is correct |
31 |
Correct |
95 ms |
159612 KB |
Output is correct |
32 |
Correct |
97 ms |
159608 KB |
Output is correct |
33 |
Execution timed out |
1540 ms |
194428 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |