# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1085574 |
2024-09-08T12:38:36 Z |
4QT0R |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
23 ms |
3220 KB |
#include <bits/stdc++.h>
using namespace std;
char wej[200003];
vector<int> pref[3];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,k;
cin >> n >> k;
pref[0].resize(n+1);
pref[1].resize(n+1);
pref[2].resize(n+1);
for (int i = 1; i<=n; i++){
cin >> wej[i];
pref[0][i]=pref[0][i-1];
pref[1][i]=pref[1][i-1];
pref[2][i]=pref[2][i-1];
if (wej[i]=='J')pref[0][i]++;
else if (wej[i]=='O')pref[1][i]++;
else pref[2][i]++;
}
int ans=n+1;
for (int i = 1; i<=n+1-3*k; i++){
int p0=i,p1=lower_bound(pref[0].begin()+p0,pref[0].end(),pref[0][i-1]+k)-pref[0].begin();
if (p1>n)continue;
int p2=lower_bound(pref[1].begin()+p1,pref[1].end(),pref[1][p1-1]+k)-pref[1].begin();
if (p2>n)continue;
int p3=lower_bound(pref[2].begin()+p2,pref[2].end(),pref[2][p2-1]+k)-pref[2].begin();
if (p3>n)continue;
ans=min(ans,p3-p0+1-3*k);
}
if (ans>n)cout << "-1\n";
else cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 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 |
344 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 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 |
344 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
504 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 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 |
344 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
504 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
17 ms |
2908 KB |
Output is correct |
37 |
Correct |
17 ms |
3160 KB |
Output is correct |
38 |
Correct |
23 ms |
3216 KB |
Output is correct |
39 |
Correct |
19 ms |
3164 KB |
Output is correct |
40 |
Correct |
14 ms |
3164 KB |
Output is correct |
41 |
Correct |
17 ms |
3164 KB |
Output is correct |
42 |
Correct |
20 ms |
3216 KB |
Output is correct |
43 |
Correct |
7 ms |
2140 KB |
Output is correct |
44 |
Correct |
10 ms |
2396 KB |
Output is correct |
45 |
Correct |
14 ms |
2972 KB |
Output is correct |
46 |
Correct |
17 ms |
3176 KB |
Output is correct |
47 |
Correct |
13 ms |
3220 KB |
Output is correct |
48 |
Correct |
12 ms |
3220 KB |
Output is correct |
49 |
Correct |
8 ms |
2136 KB |
Output is correct |
50 |
Correct |
13 ms |
3220 KB |
Output is correct |
51 |
Correct |
12 ms |
3216 KB |
Output is correct |
52 |
Correct |
6 ms |
3084 KB |
Output is correct |
53 |
Correct |
7 ms |
3216 KB |
Output is correct |
54 |
Correct |
10 ms |
3164 KB |
Output is correct |
55 |
Correct |
5 ms |
3032 KB |
Output is correct |
56 |
Correct |
3 ms |
3164 KB |
Output is correct |