# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
868615 |
2023-11-01T02:19:20 Z |
12345678 |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
23 ms |
3556 KB |
#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5;
int n, k, mp[100], qs[3][nx], res=INT_MAX;
string s;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>k>>s;
mp['J']=0; mp['O']=1; mp['I']=2;
for (int i=1; i<=n; i++) qs[0][i]=qs[0][i-1], qs[1][i]=qs[1][i-1], qs[2][i]=qs[2][i-1], qs[mp[s[i-1]]][i]++;
qs[0][n+1]=qs[1][n+1]=qs[2][n+1]=INT_MAX;
//for (int i=1; i<=n+1; i++) cout<<i<<' '<<qs[0][i]<<' '<<qs[1][i]<<' '<<qs[2][i]<<'\n';
for (int i=1; i<=n; i++)
{
int c=i;
int v1=lower_bound(qs[0]+1, qs[0]+n+2, qs[0][c-1]+k)-(qs[0])+1;
int v2=lower_bound(qs[1]+1, qs[1]+n+2, qs[1][v1-1]+k)-(qs[1])+1;
int v3=lower_bound(qs[2]+1, qs[2]+n+2, qs[2][v2-1]+k)-(qs[2]);
//cout<<i<<' '<<v1<<' '<<v2<<' '<<v3<<'\n';
if (v1>=n+1||v2>=n+1||v3>=n+1) continue;
res=min(res, v3-i+1-3*k);
}
if (res==INT_MAX) cout<<-1;
else cout<<res;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:14:105: warning: array subscript has type 'char' [-Wchar-subscripts]
14 | for (int i=1; i<=n; i++) qs[0][i]=qs[0][i-1], qs[1][i]=qs[1][i-1], qs[2][i]=qs[2][i-1], qs[mp[s[i-1]]][i]++;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
360 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 |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
460 KB |
Output is correct |
11 |
Correct |
1 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 |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
360 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 |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
460 KB |
Output is correct |
11 |
Correct |
1 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 |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
464 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
468 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 |
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 |
348 KB |
Output is correct |
33 |
Correct |
1 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 |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
360 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 |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
460 KB |
Output is correct |
11 |
Correct |
1 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 |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
464 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
468 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 |
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 |
348 KB |
Output is correct |
33 |
Correct |
1 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 |
23 ms |
3048 KB |
Output is correct |
37 |
Correct |
22 ms |
3208 KB |
Output is correct |
38 |
Correct |
21 ms |
3304 KB |
Output is correct |
39 |
Correct |
20 ms |
3304 KB |
Output is correct |
40 |
Correct |
17 ms |
3304 KB |
Output is correct |
41 |
Correct |
19 ms |
3300 KB |
Output is correct |
42 |
Correct |
21 ms |
3300 KB |
Output is correct |
43 |
Correct |
12 ms |
2140 KB |
Output is correct |
44 |
Correct |
13 ms |
2572 KB |
Output is correct |
45 |
Correct |
16 ms |
3304 KB |
Output is correct |
46 |
Correct |
16 ms |
3304 KB |
Output is correct |
47 |
Correct |
16 ms |
3304 KB |
Output is correct |
48 |
Correct |
16 ms |
3304 KB |
Output is correct |
49 |
Correct |
11 ms |
2268 KB |
Output is correct |
50 |
Correct |
23 ms |
3304 KB |
Output is correct |
51 |
Correct |
16 ms |
3304 KB |
Output is correct |
52 |
Correct |
12 ms |
3056 KB |
Output is correct |
53 |
Correct |
13 ms |
3304 KB |
Output is correct |
54 |
Correct |
15 ms |
3304 KB |
Output is correct |
55 |
Correct |
13 ms |
3556 KB |
Output is correct |
56 |
Correct |
13 ms |
3304 KB |
Output is correct |