# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
971466 |
2024-04-28T14:57:03 Z |
AndrijaM |
JJOOII 2 (JOI20_ho_t2) |
C++14 |
|
4 ms |
2692 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const long long maxn = 2e5 + 5;
const long long logn=25;
const long long mod=1e9+7;
int vJ[maxn];
int vO[maxn];
int vI[maxn];
int cj=0;
int ci=0;
int co=0;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin>>n>>k;
string s;
cin>>s;
for(int i=0;i<n;i++)
{
if(s[i]=='J')
{
cj++;
vJ[cj]=i;
}
if(s[i]=='O')
{
co++;
vO[co]=i;
}
if(s[i]=='I')
{
ci++;
vI[ci]=i;
}
}
int pj=1;
int po=1;
int pi=1;
int ans=n+1;
while(pj+k-1<=cj && po+k-1<=co && pi+k-1<=ci)
{
while(po+k-1<=co && vO[po]<=vJ[pj+k-1])
{
po++;
}
if(po+k-1<=co)
{
while(pi-k+1<=ci && vI[pi]<=vO[po+k-1])
{
pi++;
}
}
if(pj+k-1<=cj && po+k-1<=co && pi+k-1<=ci)
{
ans=min(ans,vI[pi+k-1]-vJ[pj]+1-3*k);
}
pj++;
}
if(ans==n+1)
{
cout<<-1<<endl;
}
else
{
cout<<ans<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 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 |
600 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 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 |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 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 |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
408 KB |
Output is correct |
36 |
Correct |
4 ms |
2536 KB |
Output is correct |
37 |
Correct |
4 ms |
2532 KB |
Output is correct |
38 |
Correct |
4 ms |
2536 KB |
Output is correct |
39 |
Correct |
3 ms |
2536 KB |
Output is correct |
40 |
Correct |
3 ms |
2536 KB |
Output is correct |
41 |
Correct |
3 ms |
2532 KB |
Output is correct |
42 |
Correct |
4 ms |
2536 KB |
Output is correct |
43 |
Correct |
2 ms |
1628 KB |
Output is correct |
44 |
Correct |
2 ms |
2024 KB |
Output is correct |
45 |
Correct |
3 ms |
2536 KB |
Output is correct |
46 |
Correct |
3 ms |
2536 KB |
Output is correct |
47 |
Correct |
3 ms |
2692 KB |
Output is correct |
48 |
Correct |
3 ms |
2536 KB |
Output is correct |
49 |
Correct |
2 ms |
1764 KB |
Output is correct |
50 |
Correct |
2 ms |
2536 KB |
Output is correct |
51 |
Correct |
2 ms |
2408 KB |
Output is correct |
52 |
Correct |
3 ms |
2280 KB |
Output is correct |
53 |
Correct |
3 ms |
2536 KB |
Output is correct |
54 |
Correct |
2 ms |
2536 KB |
Output is correct |
55 |
Correct |
2 ms |
2404 KB |
Output is correct |
56 |
Correct |
2 ms |
2536 KB |
Output is correct |