# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
922813 |
2024-02-06T06:55:44 Z |
dimashhh |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
8 ms |
4640 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 12, MOD = 1e9 + 7;
typedef long long ll;
int n,k,A[N],B[N],C[N];
string s;
vector<int> a,b,c;
void test(){
cin >> n >> k >> s;
s = "#" + s;
for(int i = 1;i <= n;i++){
A[i] = A[i - 1];
B[i] = B[i - 1];
C[i] = C[i - 1];
if(s[i] == 'J'){
A[i]++;
a.push_back(i);
}else if(s[i] == 'O'){
B[i]++;
b.push_back(i);
}else{
C[i]++;
c.push_back(i);
}
}
if(min({(int)a.size(),(int)b.size(),(int)c.size()}) < k){
cout << -1 << '\n';
return;
}
int res = 1e9;
for(int i = 0;i < (int)a.size();i++){
if(i + k - 1 >= (int)a.size()) break;
int l = -1,r = c.size() - k + 1;
while(r - l > 1){
int j = (l + r) >> 1;
if(B[c[j]] - B[a[i + k - 1]] >= k){
res = min(res,n - k * 3 - (a[i] - 1) - (n - c[j + k - 1]));
r = j;
}else{
l = j;
}
}
for(int j = (int)c.size() - k;j >= 0;j--){
if(B[c[j]] - B[a[i + k - 1]] >= k){
// res = min(res,n - k * 3 - (a[i] - 1) - (n - c[j + k - 1]));
}else break;
}
}
if(res == 1e9) res = -1;
cout<< res << '\n';
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int T = 1;
// cin >> T;
while (T--)
test();
}
# |
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 |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
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 |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
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 |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 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 |
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 |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
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 |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 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 |
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 |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
6 ms |
3628 KB |
Output is correct |
37 |
Correct |
8 ms |
4384 KB |
Output is correct |
38 |
Correct |
7 ms |
4388 KB |
Output is correct |
39 |
Correct |
6 ms |
4388 KB |
Output is correct |
40 |
Correct |
5 ms |
4384 KB |
Output is correct |
41 |
Correct |
6 ms |
4516 KB |
Output is correct |
42 |
Correct |
7 ms |
4388 KB |
Output is correct |
43 |
Correct |
3 ms |
2896 KB |
Output is correct |
44 |
Correct |
4 ms |
3408 KB |
Output is correct |
45 |
Correct |
5 ms |
4640 KB |
Output is correct |
46 |
Correct |
5 ms |
4388 KB |
Output is correct |
47 |
Correct |
5 ms |
4480 KB |
Output is correct |
48 |
Correct |
5 ms |
4388 KB |
Output is correct |
49 |
Correct |
3 ms |
3172 KB |
Output is correct |
50 |
Correct |
5 ms |
4640 KB |
Output is correct |
51 |
Correct |
5 ms |
4388 KB |
Output is correct |
52 |
Correct |
4 ms |
3884 KB |
Output is correct |
53 |
Correct |
4 ms |
4384 KB |
Output is correct |
54 |
Correct |
5 ms |
4256 KB |
Output is correct |
55 |
Correct |
4 ms |
4260 KB |
Output is correct |
56 |
Correct |
3 ms |
4512 KB |
Output is correct |