#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> a,b,c;
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n,k;
cin>>n>>k;
string s;
cin>>s;
for(int i=0;i<s.length();i++)
{
if(s[i]=='J')
a.push_back(i);
if(s[i]=='O')
b.push_back(i);
if(s[i]=='I')
c.push_back(i);
}
int wynik=1000000000;
for(int i=0;i<a.size();i++)
{
int nas=i+k-1;
if(nas>=a.size())
break;
int gdzie1=lower_bound(b.begin(),b.end(),a[nas])-b.begin()+k-1;
if(gdzie1>=b.size())
continue;
// cout<<"zyje\n";
int gdzie2=lower_bound(c.begin(),c.end(),b[gdzie1])-c.begin()+k-1;
if(gdzie2>=c.size())
continue;
//cout<<"zyje2\n";
//cout<<a[i]<<" "<<a[nas]<<" "<<b[gdzie1]<<" "<<b[gdzie1-k+1]<<"\n";
wynik=min(wynik,c[gdzie2]-a[i]+1-3*k);
}
if(wynik==1000000000)
cout<<"-1";
else cout<<wynik;
return 0;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:15:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(int i=0;i<s.length();i++)
| ~^~~~~~~~~~~
ho_t2.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i=0;i<a.size();i++)
| ~^~~~~~~~~
ho_t2.cpp:28:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if(nas>=a.size())
| ~~~^~~~~~~~~~
ho_t2.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | if(gdzie1>=b.size())
| ~~~~~~^~~~~~~~~~
ho_t2.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if(gdzie2>=c.size())
| ~~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
320 KB |
Output is correct |
30 |
Correct |
1 ms |
324 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
320 KB |
Output is correct |
30 |
Correct |
1 ms |
324 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
12 ms |
1604 KB |
Output is correct |
37 |
Correct |
13 ms |
1824 KB |
Output is correct |
38 |
Correct |
11 ms |
1964 KB |
Output is correct |
39 |
Correct |
11 ms |
1900 KB |
Output is correct |
40 |
Correct |
8 ms |
2008 KB |
Output is correct |
41 |
Correct |
11 ms |
1940 KB |
Output is correct |
42 |
Correct |
13 ms |
1824 KB |
Output is correct |
43 |
Correct |
5 ms |
1268 KB |
Output is correct |
44 |
Correct |
8 ms |
1496 KB |
Output is correct |
45 |
Correct |
7 ms |
2000 KB |
Output is correct |
46 |
Correct |
7 ms |
2000 KB |
Output is correct |
47 |
Correct |
7 ms |
2008 KB |
Output is correct |
48 |
Correct |
8 ms |
2008 KB |
Output is correct |
49 |
Correct |
5 ms |
1336 KB |
Output is correct |
50 |
Correct |
9 ms |
1996 KB |
Output is correct |
51 |
Correct |
10 ms |
2028 KB |
Output is correct |
52 |
Correct |
4 ms |
1496 KB |
Output is correct |
53 |
Correct |
6 ms |
1740 KB |
Output is correct |
54 |
Correct |
4 ms |
2012 KB |
Output is correct |
55 |
Correct |
4 ms |
2000 KB |
Output is correct |
56 |
Correct |
3 ms |
1980 KB |
Output is correct |