# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
996852 |
2024-06-11T10:36:46 Z |
vako_p |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
771 ms |
57232 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mxN = 3e5 + 5;
ll n,k;
string s;
map<ll,map<char,ll>> p;
ll find(char ch, ll i){
ll l = i - 1, r = n;
while(r > l + 1){
ll mid = l + (r - l) / 2;
if(i == 0){
if(p[mid][ch] >= k) r = mid;
else l = mid;
continue;
}
if(p[mid][ch] - p[i - 1][ch] >= k) r = mid;
else l = mid;
}
return r;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k >> s;
for(int i = 0; i < n; i++){
if(i != 0){
p[i]['J'] = p[i - 1]['J'];
p[i]['O'] = p[i - 1]['O'];
p[i]['I'] = p[i - 1]['I'];
}
p[i][s[i]]++;
}
ll ans = 1e9;
for(int i = 0; i < n; i++){
if(s[i] == 'J'){
ll r = find('J', i);
r = find('O', r);
r = find('I', r);
if(r == n) continue;
ans = min(ans, r - i + 1 - 3 * k);
}
}
if(ans == 1e9) cout << -1;
else cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
452 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
452 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
1116 KB |
Output is correct |
16 |
Correct |
4 ms |
1312 KB |
Output is correct |
17 |
Correct |
3 ms |
1116 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
4 ms |
1116 KB |
Output is correct |
20 |
Correct |
3 ms |
1116 KB |
Output is correct |
21 |
Correct |
3 ms |
1116 KB |
Output is correct |
22 |
Correct |
3 ms |
1116 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
3 ms |
1112 KB |
Output is correct |
25 |
Correct |
3 ms |
1112 KB |
Output is correct |
26 |
Correct |
3 ms |
1116 KB |
Output is correct |
27 |
Correct |
3 ms |
1116 KB |
Output is correct |
28 |
Correct |
3 ms |
1116 KB |
Output is correct |
29 |
Correct |
3 ms |
1112 KB |
Output is correct |
30 |
Correct |
3 ms |
1116 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
1116 KB |
Output is correct |
33 |
Correct |
3 ms |
1116 KB |
Output is correct |
34 |
Correct |
3 ms |
1312 KB |
Output is correct |
35 |
Correct |
2 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
452 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
1116 KB |
Output is correct |
16 |
Correct |
4 ms |
1312 KB |
Output is correct |
17 |
Correct |
3 ms |
1116 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
4 ms |
1116 KB |
Output is correct |
20 |
Correct |
3 ms |
1116 KB |
Output is correct |
21 |
Correct |
3 ms |
1116 KB |
Output is correct |
22 |
Correct |
3 ms |
1116 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
3 ms |
1112 KB |
Output is correct |
25 |
Correct |
3 ms |
1112 KB |
Output is correct |
26 |
Correct |
3 ms |
1116 KB |
Output is correct |
27 |
Correct |
3 ms |
1116 KB |
Output is correct |
28 |
Correct |
3 ms |
1116 KB |
Output is correct |
29 |
Correct |
3 ms |
1112 KB |
Output is correct |
30 |
Correct |
3 ms |
1116 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
1116 KB |
Output is correct |
33 |
Correct |
3 ms |
1116 KB |
Output is correct |
34 |
Correct |
3 ms |
1312 KB |
Output is correct |
35 |
Correct |
2 ms |
1116 KB |
Output is correct |
36 |
Correct |
641 ms |
52984 KB |
Output is correct |
37 |
Correct |
716 ms |
57148 KB |
Output is correct |
38 |
Correct |
694 ms |
57144 KB |
Output is correct |
39 |
Correct |
749 ms |
56540 KB |
Output is correct |
40 |
Correct |
635 ms |
57052 KB |
Output is correct |
41 |
Correct |
723 ms |
56968 KB |
Output is correct |
42 |
Correct |
771 ms |
57048 KB |
Output is correct |
43 |
Correct |
337 ms |
35652 KB |
Output is correct |
44 |
Correct |
453 ms |
44348 KB |
Output is correct |
45 |
Correct |
610 ms |
56980 KB |
Output is correct |
46 |
Correct |
599 ms |
56996 KB |
Output is correct |
47 |
Correct |
594 ms |
57052 KB |
Output is correct |
48 |
Correct |
592 ms |
56964 KB |
Output is correct |
49 |
Correct |
372 ms |
38108 KB |
Output is correct |
50 |
Correct |
609 ms |
57076 KB |
Output is correct |
51 |
Correct |
609 ms |
57060 KB |
Output is correct |
52 |
Correct |
394 ms |
55004 KB |
Output is correct |
53 |
Correct |
420 ms |
57056 KB |
Output is correct |
54 |
Correct |
659 ms |
57232 KB |
Output is correct |
55 |
Correct |
489 ms |
57160 KB |
Output is correct |
56 |
Correct |
371 ms |
57048 KB |
Output is correct |