#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli test=1;
for(;test>0;--test)
{
lli n,k,ans;
string s;
cin>>n>>k>>s;
ans=n;
vi j,o,i;
for(lli i1=0;i1<s.size();++i1)
{
if(s[i1]=='J')
j.pb(i1);
else if(s[i1]=='O')
o.pb(i1);
else
i.pb(i1);
}
lli l=0;
for(lli i1=0;i1<j.size();++i1)
{
lli pans=0;
if(j.size()-i1>=k)
pans+=j[i1+k-1]-j[i1]+1-k;
else
continue;
l=j[i1+k-1]+1;
lli it1=lower_bound(all(o),l)-o.begin();
if(o.size()-it1>=k)
pans+=o[it1+k-1]-o[it1]+1-k;
else
continue;
pans+=o[it1]-l;
l=o[it1+k-1]+1;
int it2=lower_bound(all(i),l)-i.begin();
if(i.size()-it2>=k)
pans+=i[it2+k-1]-i[it2]+1-k;
else
continue;
pans+=i[it2]-l;
ans=min(ans,pans);
}
if(ans==n)
cout<<"-1"<<endl;
else
cout<<ans<<endl;
}
return(0);
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:30:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(lli i1=0;i1<s.size();++i1)
~~^~~~~~~~~
ho_t2.cpp:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(lli i1=0;i1<j.size();++i1)
~~^~~~~~~~~
ho_t2.cpp:43:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(j.size()-i1>=k)
~~~~~~~~~~~^~~
ho_t2.cpp:49:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(o.size()-it1>=k)
~~~~~~~~~~~~^~~
ho_t2.cpp:56:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(i.size()-it2>=k)
~~~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
512 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
4 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
512 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
4 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
4 ms |
384 KB |
Output is correct |
36 |
Correct |
17 ms |
2468 KB |
Output is correct |
37 |
Correct |
16 ms |
2908 KB |
Output is correct |
38 |
Correct |
16 ms |
3000 KB |
Output is correct |
39 |
Correct |
15 ms |
2936 KB |
Output is correct |
40 |
Correct |
13 ms |
2936 KB |
Output is correct |
41 |
Correct |
15 ms |
3064 KB |
Output is correct |
42 |
Correct |
16 ms |
2876 KB |
Output is correct |
43 |
Correct |
9 ms |
1940 KB |
Output is correct |
44 |
Correct |
10 ms |
2136 KB |
Output is correct |
45 |
Correct |
12 ms |
3064 KB |
Output is correct |
46 |
Correct |
13 ms |
3004 KB |
Output is correct |
47 |
Correct |
13 ms |
2936 KB |
Output is correct |
48 |
Correct |
14 ms |
2876 KB |
Output is correct |
49 |
Correct |
10 ms |
1920 KB |
Output is correct |
50 |
Correct |
13 ms |
2992 KB |
Output is correct |
51 |
Correct |
12 ms |
3068 KB |
Output is correct |
52 |
Correct |
9 ms |
2364 KB |
Output is correct |
53 |
Correct |
10 ms |
2936 KB |
Output is correct |
54 |
Correct |
9 ms |
3328 KB |
Output is correct |
55 |
Correct |
9 ms |
3328 KB |
Output is correct |
56 |
Correct |
8 ms |
3328 KB |
Output is correct |