//from duckindog wth depression
#include<bits/stdc++.h>
using namespace std;
//#define LOCAL
#ifndef LOCAL
#include "paint.h"
#endif // LOCAL
const int N = 500 + 10;
int f[N];
int minimumInstructions(int n, int m, int k, vector<int> C, vector<int> A, vector<vector<int>> B) {
memset(f, 63, sizeof f);
f[0] = 0;
for (int l = 0; l < n - m + 1; ++l) {
int r = l + m - 1;
bool pass = 0;
for (int x = 0; x < m; ++x) {
bool good = 1;
for (int i = l; i <= r; ++i) {
int y = (i - l + x) % m;
good &= binary_search(B[y].begin(), B[y].end(), C[i]);
}
pass |= good;
}
if (pass) {
for (int i = l; i <= r; ++i)
f[r + 1] = min(f[r + 1], f[i] + 1);
}
}
return f[n] > 1e9 ? -1 : f[n];
}
#ifdef LOCAL
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("duck.inp", "r")) {
freopen("duck.inp", "r", stdin);
freopen("duck.out", "w", stdout);
}
int n, m, k; cin >> n >> m >> k;
vector<int> C, A;
vector<vector<int>> B;
for (int i = 1; i <= n; ++i) {
int x; cin >> x;
C.push_back(x);
}
for (int i = 1; i <= m; ++i) {
int a; cin >> a; A.push_back(a);
vector<int> vt;
for (int j = 1; j <= a; ++j) {
int x; cin >> x;
vt.push_back(x);
}
sort(vt.begin(), vt.end());
B.push_back(vt);
}
cout << minimumInstructions(n, m, k, C, A, B);
}
#endif // LOCAL
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
167 ms |
452 KB |
Output is correct |
14 |
Correct |
166 ms |
448 KB |
Output is correct |
15 |
Correct |
167 ms |
600 KB |
Output is correct |
16 |
Correct |
166 ms |
348 KB |
Output is correct |
17 |
Correct |
168 ms |
444 KB |
Output is correct |
18 |
Correct |
166 ms |
348 KB |
Output is correct |
19 |
Correct |
239 ms |
348 KB |
Output is correct |
20 |
Correct |
240 ms |
348 KB |
Output is correct |
21 |
Correct |
246 ms |
448 KB |
Output is correct |
22 |
Correct |
731 ms |
1628 KB |
Output is correct |
23 |
Correct |
746 ms |
1848 KB |
Output is correct |
24 |
Correct |
746 ms |
1796 KB |
Output is correct |
25 |
Runtime error |
3 ms |
860 KB |
Execution killed with signal 11 |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
167 ms |
452 KB |
Output is correct |
14 |
Correct |
166 ms |
448 KB |
Output is correct |
15 |
Correct |
167 ms |
600 KB |
Output is correct |
16 |
Correct |
166 ms |
348 KB |
Output is correct |
17 |
Correct |
168 ms |
444 KB |
Output is correct |
18 |
Correct |
166 ms |
348 KB |
Output is correct |
19 |
Correct |
239 ms |
348 KB |
Output is correct |
20 |
Correct |
240 ms |
348 KB |
Output is correct |
21 |
Correct |
246 ms |
448 KB |
Output is correct |
22 |
Correct |
0 ms |
600 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
5 ms |
348 KB |
Output is correct |
33 |
Correct |
89 ms |
348 KB |
Output is correct |
34 |
Correct |
104 ms |
348 KB |
Output is correct |
35 |
Correct |
34 ms |
348 KB |
Output is correct |
36 |
Correct |
72 ms |
344 KB |
Output is correct |
37 |
Correct |
58 ms |
440 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
86 ms |
440 KB |
Output is correct |
41 |
Correct |
49 ms |
596 KB |
Output is correct |
42 |
Correct |
53 ms |
344 KB |
Output is correct |
43 |
Correct |
11 ms |
344 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
2 ms |
348 KB |
Output is correct |
46 |
Correct |
6 ms |
344 KB |
Output is correct |
47 |
Correct |
8 ms |
348 KB |
Output is correct |
48 |
Correct |
10 ms |
604 KB |
Output is correct |
49 |
Correct |
12 ms |
344 KB |
Output is correct |
50 |
Correct |
170 ms |
448 KB |
Output is correct |
51 |
Correct |
164 ms |
444 KB |
Output is correct |
52 |
Correct |
168 ms |
344 KB |
Output is correct |
53 |
Correct |
170 ms |
592 KB |
Output is correct |
54 |
Correct |
165 ms |
344 KB |
Output is correct |
55 |
Correct |
168 ms |
444 KB |
Output is correct |
56 |
Correct |
244 ms |
464 KB |
Output is correct |
57 |
Correct |
167 ms |
344 KB |
Output is correct |
58 |
Correct |
241 ms |
344 KB |
Output is correct |
59 |
Correct |
174 ms |
444 KB |
Output is correct |
60 |
Correct |
248 ms |
348 KB |
Output is correct |
61 |
Correct |
178 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
436 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
167 ms |
452 KB |
Output is correct |
16 |
Correct |
166 ms |
448 KB |
Output is correct |
17 |
Correct |
167 ms |
600 KB |
Output is correct |
18 |
Correct |
166 ms |
348 KB |
Output is correct |
19 |
Correct |
168 ms |
444 KB |
Output is correct |
20 |
Correct |
166 ms |
348 KB |
Output is correct |
21 |
Correct |
239 ms |
348 KB |
Output is correct |
22 |
Correct |
240 ms |
348 KB |
Output is correct |
23 |
Correct |
246 ms |
448 KB |
Output is correct |
24 |
Correct |
731 ms |
1628 KB |
Output is correct |
25 |
Correct |
746 ms |
1848 KB |
Output is correct |
26 |
Correct |
746 ms |
1796 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
5 ms |
348 KB |
Output is correct |
36 |
Correct |
89 ms |
348 KB |
Output is correct |
37 |
Correct |
104 ms |
348 KB |
Output is correct |
38 |
Correct |
34 ms |
348 KB |
Output is correct |
39 |
Correct |
72 ms |
344 KB |
Output is correct |
40 |
Correct |
58 ms |
440 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
86 ms |
440 KB |
Output is correct |
44 |
Correct |
49 ms |
596 KB |
Output is correct |
45 |
Correct |
53 ms |
344 KB |
Output is correct |
46 |
Correct |
11 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
2 ms |
348 KB |
Output is correct |
49 |
Correct |
6 ms |
344 KB |
Output is correct |
50 |
Correct |
8 ms |
348 KB |
Output is correct |
51 |
Correct |
10 ms |
604 KB |
Output is correct |
52 |
Correct |
12 ms |
344 KB |
Output is correct |
53 |
Correct |
170 ms |
448 KB |
Output is correct |
54 |
Correct |
164 ms |
444 KB |
Output is correct |
55 |
Correct |
168 ms |
344 KB |
Output is correct |
56 |
Correct |
170 ms |
592 KB |
Output is correct |
57 |
Correct |
165 ms |
344 KB |
Output is correct |
58 |
Correct |
168 ms |
444 KB |
Output is correct |
59 |
Correct |
244 ms |
464 KB |
Output is correct |
60 |
Correct |
167 ms |
344 KB |
Output is correct |
61 |
Correct |
241 ms |
344 KB |
Output is correct |
62 |
Correct |
174 ms |
444 KB |
Output is correct |
63 |
Correct |
248 ms |
348 KB |
Output is correct |
64 |
Correct |
178 ms |
344 KB |
Output is correct |
65 |
Correct |
11 ms |
344 KB |
Output is correct |
66 |
Correct |
4 ms |
348 KB |
Output is correct |
67 |
Correct |
27 ms |
600 KB |
Output is correct |
68 |
Correct |
10 ms |
448 KB |
Output is correct |
69 |
Correct |
22 ms |
348 KB |
Output is correct |
70 |
Correct |
299 ms |
572 KB |
Output is correct |
71 |
Correct |
233 ms |
600 KB |
Output is correct |
72 |
Correct |
78 ms |
576 KB |
Output is correct |
73 |
Correct |
2 ms |
344 KB |
Output is correct |
74 |
Correct |
107 ms |
572 KB |
Output is correct |
75 |
Correct |
176 ms |
348 KB |
Output is correct |
76 |
Correct |
163 ms |
1952 KB |
Output is correct |
77 |
Correct |
9 ms |
2136 KB |
Output is correct |
78 |
Correct |
33 ms |
2396 KB |
Output is correct |
79 |
Correct |
53 ms |
348 KB |
Output is correct |
80 |
Correct |
55 ms |
348 KB |
Output is correct |
81 |
Correct |
59 ms |
600 KB |
Output is correct |
82 |
Correct |
56 ms |
444 KB |
Output is correct |
83 |
Correct |
57 ms |
344 KB |
Output is correct |
84 |
Correct |
456 ms |
628 KB |
Output is correct |
85 |
Correct |
459 ms |
852 KB |
Output is correct |
86 |
Correct |
457 ms |
848 KB |
Output is correct |
87 |
Correct |
451 ms |
600 KB |
Output is correct |
88 |
Correct |
455 ms |
848 KB |
Output is correct |
89 |
Correct |
453 ms |
624 KB |
Output is correct |
90 |
Correct |
862 ms |
2560 KB |
Output is correct |
91 |
Correct |
838 ms |
2556 KB |
Output is correct |
92 |
Correct |
839 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
436 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
167 ms |
452 KB |
Output is correct |
16 |
Correct |
166 ms |
448 KB |
Output is correct |
17 |
Correct |
167 ms |
600 KB |
Output is correct |
18 |
Correct |
166 ms |
348 KB |
Output is correct |
19 |
Correct |
168 ms |
444 KB |
Output is correct |
20 |
Correct |
166 ms |
348 KB |
Output is correct |
21 |
Correct |
239 ms |
348 KB |
Output is correct |
22 |
Correct |
240 ms |
348 KB |
Output is correct |
23 |
Correct |
246 ms |
448 KB |
Output is correct |
24 |
Correct |
731 ms |
1628 KB |
Output is correct |
25 |
Correct |
746 ms |
1848 KB |
Output is correct |
26 |
Correct |
746 ms |
1796 KB |
Output is correct |
27 |
Runtime error |
3 ms |
860 KB |
Execution killed with signal 11 |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
436 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
167 ms |
452 KB |
Output is correct |
16 |
Correct |
166 ms |
448 KB |
Output is correct |
17 |
Correct |
167 ms |
600 KB |
Output is correct |
18 |
Correct |
166 ms |
348 KB |
Output is correct |
19 |
Correct |
168 ms |
444 KB |
Output is correct |
20 |
Correct |
166 ms |
348 KB |
Output is correct |
21 |
Correct |
239 ms |
348 KB |
Output is correct |
22 |
Correct |
240 ms |
348 KB |
Output is correct |
23 |
Correct |
246 ms |
448 KB |
Output is correct |
24 |
Correct |
731 ms |
1628 KB |
Output is correct |
25 |
Correct |
746 ms |
1848 KB |
Output is correct |
26 |
Correct |
746 ms |
1796 KB |
Output is correct |
27 |
Runtime error |
3 ms |
860 KB |
Execution killed with signal 11 |
28 |
Halted |
0 ms |
0 KB |
- |