#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b) {
vector<int> p[k + 1];
map<pair<int, int>, bool> mp;
for(int i = 0; i < m; ++i) {
for(auto x: b[i]) {
p[x].pb(i);
mp[{i, x}] = 1;
}
}
vector<bool> can(n, false);
for(int i = 0; i + m - 1 < n; ++i) {
for(int x: p[c[i]]) {
bool ok = true;
for(int times = 0; times < m && ok; ++times) {
if(!mp[{(x + times) % m, c[i + times]}]) ok = false;
}
if(ok) {
can[i] = true;
break;
}
}
}
set<int> good;
forn(i, n) if(can[i]) good.insert(i);
int lst = -1e9, ans = 0;
for(int i = 0; i < n; ++i) {
if(lst + m - 1 >= i) continue;
++ans;
if(can[i]) {
lst = i;
} else {
auto it = good.lower_bound(i);
if(it == good.begin()) return -1;
--it;
if(*it + m - 1 < i) return -1;
lst = *it;
}
}
return ans;
}
/*
void solve() {
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while(t--) {
solve();
}
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
296 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
3 ms |
2644 KB |
Output is correct |
14 |
Correct |
4 ms |
2644 KB |
Output is correct |
15 |
Correct |
3 ms |
2644 KB |
Output is correct |
16 |
Correct |
4 ms |
2644 KB |
Output is correct |
17 |
Correct |
3 ms |
2732 KB |
Output is correct |
18 |
Correct |
4 ms |
2644 KB |
Output is correct |
19 |
Correct |
3 ms |
2772 KB |
Output is correct |
20 |
Correct |
2 ms |
2772 KB |
Output is correct |
21 |
Correct |
3 ms |
2772 KB |
Output is correct |
22 |
Correct |
64 ms |
13404 KB |
Output is correct |
23 |
Correct |
53 ms |
13436 KB |
Output is correct |
24 |
Correct |
48 ms |
13320 KB |
Output is correct |
25 |
Correct |
6 ms |
1364 KB |
Output is correct |
26 |
Correct |
5 ms |
1364 KB |
Output is correct |
27 |
Correct |
5 ms |
952 KB |
Output is correct |
28 |
Correct |
3 ms |
596 KB |
Output is correct |
29 |
Correct |
3 ms |
416 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Execution timed out |
1580 ms |
5136 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
296 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
3 ms |
2644 KB |
Output is correct |
14 |
Correct |
4 ms |
2644 KB |
Output is correct |
15 |
Correct |
3 ms |
2644 KB |
Output is correct |
16 |
Correct |
4 ms |
2644 KB |
Output is correct |
17 |
Correct |
3 ms |
2732 KB |
Output is correct |
18 |
Correct |
4 ms |
2644 KB |
Output is correct |
19 |
Correct |
3 ms |
2772 KB |
Output is correct |
20 |
Correct |
2 ms |
2772 KB |
Output is correct |
21 |
Correct |
3 ms |
2772 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
300 KB |
Output is correct |
25 |
Correct |
1 ms |
296 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
300 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
3 ms |
2260 KB |
Output is correct |
34 |
Correct |
2 ms |
1840 KB |
Output is correct |
35 |
Correct |
2 ms |
1620 KB |
Output is correct |
36 |
Correct |
3 ms |
2644 KB |
Output is correct |
37 |
Correct |
2 ms |
2132 KB |
Output is correct |
38 |
Correct |
2 ms |
2352 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
2 ms |
2100 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
2 ms |
2516 KB |
Output is correct |
43 |
Correct |
2 ms |
2484 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
5 ms |
2644 KB |
Output is correct |
51 |
Correct |
3 ms |
2644 KB |
Output is correct |
52 |
Correct |
3 ms |
2732 KB |
Output is correct |
53 |
Correct |
4 ms |
2736 KB |
Output is correct |
54 |
Correct |
3 ms |
2644 KB |
Output is correct |
55 |
Correct |
3 ms |
2644 KB |
Output is correct |
56 |
Correct |
3 ms |
2772 KB |
Output is correct |
57 |
Correct |
2 ms |
340 KB |
Output is correct |
58 |
Correct |
2 ms |
2772 KB |
Output is correct |
59 |
Correct |
3 ms |
308 KB |
Output is correct |
60 |
Correct |
2 ms |
2740 KB |
Output is correct |
61 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
296 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
3 ms |
2644 KB |
Output is correct |
16 |
Correct |
4 ms |
2644 KB |
Output is correct |
17 |
Correct |
3 ms |
2644 KB |
Output is correct |
18 |
Correct |
4 ms |
2644 KB |
Output is correct |
19 |
Correct |
3 ms |
2732 KB |
Output is correct |
20 |
Correct |
4 ms |
2644 KB |
Output is correct |
21 |
Correct |
3 ms |
2772 KB |
Output is correct |
22 |
Correct |
2 ms |
2772 KB |
Output is correct |
23 |
Correct |
3 ms |
2772 KB |
Output is correct |
24 |
Correct |
64 ms |
13404 KB |
Output is correct |
25 |
Correct |
53 ms |
13436 KB |
Output is correct |
26 |
Correct |
48 ms |
13320 KB |
Output is correct |
27 |
Correct |
1 ms |
300 KB |
Output is correct |
28 |
Correct |
1 ms |
296 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
300 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
3 ms |
2260 KB |
Output is correct |
37 |
Correct |
2 ms |
1840 KB |
Output is correct |
38 |
Correct |
2 ms |
1620 KB |
Output is correct |
39 |
Correct |
3 ms |
2644 KB |
Output is correct |
40 |
Correct |
2 ms |
2132 KB |
Output is correct |
41 |
Correct |
2 ms |
2352 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
2 ms |
2100 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
2 ms |
2516 KB |
Output is correct |
46 |
Correct |
2 ms |
2484 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
5 ms |
2644 KB |
Output is correct |
54 |
Correct |
3 ms |
2644 KB |
Output is correct |
55 |
Correct |
3 ms |
2732 KB |
Output is correct |
56 |
Correct |
4 ms |
2736 KB |
Output is correct |
57 |
Correct |
3 ms |
2644 KB |
Output is correct |
58 |
Correct |
3 ms |
2644 KB |
Output is correct |
59 |
Correct |
3 ms |
2772 KB |
Output is correct |
60 |
Correct |
2 ms |
340 KB |
Output is correct |
61 |
Correct |
2 ms |
2772 KB |
Output is correct |
62 |
Correct |
3 ms |
308 KB |
Output is correct |
63 |
Correct |
2 ms |
2740 KB |
Output is correct |
64 |
Correct |
2 ms |
340 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
3 ms |
340 KB |
Output is correct |
68 |
Correct |
2 ms |
340 KB |
Output is correct |
69 |
Correct |
3 ms |
340 KB |
Output is correct |
70 |
Correct |
26 ms |
3156 KB |
Output is correct |
71 |
Correct |
15 ms |
2936 KB |
Output is correct |
72 |
Correct |
8 ms |
2616 KB |
Output is correct |
73 |
Correct |
5 ms |
2388 KB |
Output is correct |
74 |
Correct |
11 ms |
3032 KB |
Output is correct |
75 |
Correct |
14 ms |
3340 KB |
Output is correct |
76 |
Correct |
43 ms |
12180 KB |
Output is correct |
77 |
Correct |
48 ms |
13772 KB |
Output is correct |
78 |
Correct |
65 ms |
15824 KB |
Output is correct |
79 |
Correct |
2 ms |
340 KB |
Output is correct |
80 |
Correct |
2 ms |
340 KB |
Output is correct |
81 |
Correct |
3 ms |
340 KB |
Output is correct |
82 |
Correct |
4 ms |
340 KB |
Output is correct |
83 |
Correct |
4 ms |
300 KB |
Output is correct |
84 |
Correct |
18 ms |
3848 KB |
Output is correct |
85 |
Correct |
30 ms |
3768 KB |
Output is correct |
86 |
Correct |
27 ms |
3836 KB |
Output is correct |
87 |
Correct |
20 ms |
3796 KB |
Output is correct |
88 |
Correct |
19 ms |
3768 KB |
Output is correct |
89 |
Correct |
24 ms |
3796 KB |
Output is correct |
90 |
Correct |
73 ms |
17052 KB |
Output is correct |
91 |
Correct |
67 ms |
16972 KB |
Output is correct |
92 |
Correct |
64 ms |
17024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
296 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
3 ms |
2644 KB |
Output is correct |
16 |
Correct |
4 ms |
2644 KB |
Output is correct |
17 |
Correct |
3 ms |
2644 KB |
Output is correct |
18 |
Correct |
4 ms |
2644 KB |
Output is correct |
19 |
Correct |
3 ms |
2732 KB |
Output is correct |
20 |
Correct |
4 ms |
2644 KB |
Output is correct |
21 |
Correct |
3 ms |
2772 KB |
Output is correct |
22 |
Correct |
2 ms |
2772 KB |
Output is correct |
23 |
Correct |
3 ms |
2772 KB |
Output is correct |
24 |
Correct |
64 ms |
13404 KB |
Output is correct |
25 |
Correct |
53 ms |
13436 KB |
Output is correct |
26 |
Correct |
48 ms |
13320 KB |
Output is correct |
27 |
Correct |
6 ms |
1364 KB |
Output is correct |
28 |
Correct |
5 ms |
1364 KB |
Output is correct |
29 |
Correct |
5 ms |
952 KB |
Output is correct |
30 |
Correct |
3 ms |
596 KB |
Output is correct |
31 |
Correct |
3 ms |
416 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Execution timed out |
1580 ms |
5136 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
296 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
3 ms |
2644 KB |
Output is correct |
16 |
Correct |
4 ms |
2644 KB |
Output is correct |
17 |
Correct |
3 ms |
2644 KB |
Output is correct |
18 |
Correct |
4 ms |
2644 KB |
Output is correct |
19 |
Correct |
3 ms |
2732 KB |
Output is correct |
20 |
Correct |
4 ms |
2644 KB |
Output is correct |
21 |
Correct |
3 ms |
2772 KB |
Output is correct |
22 |
Correct |
2 ms |
2772 KB |
Output is correct |
23 |
Correct |
3 ms |
2772 KB |
Output is correct |
24 |
Correct |
64 ms |
13404 KB |
Output is correct |
25 |
Correct |
53 ms |
13436 KB |
Output is correct |
26 |
Correct |
48 ms |
13320 KB |
Output is correct |
27 |
Correct |
6 ms |
1364 KB |
Output is correct |
28 |
Correct |
5 ms |
1364 KB |
Output is correct |
29 |
Correct |
5 ms |
952 KB |
Output is correct |
30 |
Correct |
3 ms |
596 KB |
Output is correct |
31 |
Correct |
3 ms |
416 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Execution timed out |
1580 ms |
5136 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |