#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define pii pair<int,int>
string s;
int OO[222222];
vector<int> II,JJ;
int main(){
int n,k;
//printf("??");
scanf("%d %d",&n,&k);
cin>>s;
//printf("SS");
for(int i=0;i<n;i++)
{
OO[i]=OO[i-1];
if(s[i]=='J') JJ.push_back(i);
else if(s[i]=='I') II.push_back(i);
else{
OO[i]=OO[i-1]+1;
if(!i) OO[i]=1;
}
if(!i) OO[i]=0;
}
int ans=1e9;
//printf("%d\n",II.size());
//printf("YY");
for(int itJ=0;itJ<JJ.size()-k+1;itJ++)
{
//printf("%d\n",JJ[itJ+k-1]);
int itI=lower_bound(II.begin(),II.end(),JJ[itJ+k-1])-II.begin();
// printf("%d\n",itI);
if(itI+k-1>=II.size()) continue;
while(OO[II[itI]]-OO[JJ[itJ+k-1]]<k) {
//printf("YOYO\n");
itI++;
if(itI+k-1>=II.size())
break;
}
if(itI+k-1>=II.size()) continue;
//printf("%d %d %d %d\n",II[itI+k-1],itI+k-1,JJ[itJ],itJ);
ans=min(ans,II[itI+k-1]-JJ[itJ]+1-(3*k));
//printf("%d ",ans);
}
if(ans>333333) printf("-1");
else
printf("%d",ans);
return 0;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int itJ=0;itJ<JJ.size()-k+1;itJ++)
| ~~~^~~~~~~~~~~~~~
ho_t2.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | if(itI+k-1>=II.size()) continue;
| ~~~~~~~^~~~~~~~~~~
ho_t2.cpp:41:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | if(itI+k-1>=II.size())
| ~~~~~~~^~~~~~~~~~~
ho_t2.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | if(itI+k-1>=II.size()) continue;
| ~~~~~~~^~~~~~~~~~~
ho_t2.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d %d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
444 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 |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
444 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 |
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 |
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 |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
444 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 |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
444 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 |
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 |
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 |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
8 ms |
2056 KB |
Output is correct |
37 |
Correct |
9 ms |
2288 KB |
Output is correct |
38 |
Correct |
9 ms |
2404 KB |
Output is correct |
39 |
Correct |
184 ms |
2408 KB |
Output is correct |
40 |
Correct |
284 ms |
2476 KB |
Output is correct |
41 |
Correct |
296 ms |
2408 KB |
Output is correct |
42 |
Correct |
48 ms |
2484 KB |
Output is correct |
43 |
Correct |
72 ms |
1548 KB |
Output is correct |
44 |
Correct |
115 ms |
1964 KB |
Output is correct |
45 |
Correct |
184 ms |
2484 KB |
Output is correct |
46 |
Correct |
190 ms |
2512 KB |
Output is correct |
47 |
Correct |
180 ms |
2476 KB |
Output is correct |
48 |
Correct |
187 ms |
2408 KB |
Output is correct |
49 |
Correct |
84 ms |
1704 KB |
Output is correct |
50 |
Correct |
183 ms |
2404 KB |
Output is correct |
51 |
Correct |
186 ms |
2508 KB |
Output is correct |
52 |
Correct |
5 ms |
1980 KB |
Output is correct |
53 |
Correct |
6 ms |
2408 KB |
Output is correct |
54 |
Correct |
5 ms |
2404 KB |
Output is correct |
55 |
Correct |
5 ms |
2660 KB |
Output is correct |
56 |
Correct |
4 ms |
2404 KB |
Output is correct |