#include<bits/stdc++.h>
#include<random>
using namespace std;
template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
#define float double
#define ss(n) fixed<<setprecision(n)
#define ll long long
#define int ll
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define rep(i,a) for(int i=1;i<=a;i++)
#define rep0(i,a) for(int i=0;i<a;i++)
#define F first
#define S second
#define uni(a) a.resize(distance(a.begin(),unique(a.begin(),a.end())));
#define unisort(a) sort(a.begin(),a.end()); uni(a);
ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);}
const ld pi=3.14159265358979323846264338327950288419716939931;
const int lar=3e18;
const int mol1=1e9+7;
const int mol2=998244353;
const int MX=3e5;
void solve()
{
int n,k;
cin>>n>>k;
string a;
cin>>a;
vector<int>a1,a2,a3;
rep0(i,a.size()){
if(a[i]=='J') a1.pb(i);
if(a[i]=='O') a2.pb(i);
if(a[i]=='I') a3.pb(i);
}
int ans=lar;
bool ok=0;
int l1=0,l2=0,l3=0;
// rep0(i,a2.size()) cout<<a2[i]<<" ";
while(a1.size()-1-l1+1>=k){
int bb=l1+k-1;
int pos=a1[bb];
while(l2+k-1<(a2.size()-1)&&a2[l2]<pos){
l2++;
}
int ppos=a2[l2+k-1];
while(l3+k-1<a3.size()-1&&a3[l3]<ppos) l3++;
if(a2[l2]>pos&&a3[l3]>ppos){
ok=1;
ans=min(ans,a3[l3+k-1]-a1[l1]+1-k*3);
}
l1++;
}
// JJOJIOIOJIOIJOII
if(ok) cout<<ans<<"\n";
else cout<<-1<<"\n";
}
signed main()
{
IO
solve();
return 0;
}
Compilation message
ho_t2.cpp: In function 'void solve()':
ho_t2.cpp:18:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | #define rep0(i,a) for(int i=0;i<a;i++)
......
39 | rep0(i,a.size()){
| ~~~~~~~~~~
ho_t2.cpp:39:5: note: in expansion of macro 'rep0'
39 | rep0(i,a.size()){
| ^~~~
ho_t2.cpp:48:27: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
48 | while(a1.size()-1-l1+1>=k){
| ~~~~~~~~~~~~~~~~^~~
ho_t2.cpp:51:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | while(l2+k-1<(a2.size()-1)&&a2[l2]<pos){
| ~~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:55:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | while(l3+k-1<a3.size()-1&&a3[l3]<ppos) l3++;
| ~~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
220 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
220 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
0 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
316 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
320 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
320 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
320 KB |
Output is correct |
35 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
220 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
0 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
316 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
320 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
320 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
320 KB |
Output is correct |
35 |
Correct |
1 ms |
324 KB |
Output is correct |
36 |
Correct |
5 ms |
2396 KB |
Output is correct |
37 |
Correct |
5 ms |
2888 KB |
Output is correct |
38 |
Correct |
6 ms |
2868 KB |
Output is correct |
39 |
Correct |
5 ms |
2976 KB |
Output is correct |
40 |
Correct |
5 ms |
3020 KB |
Output is correct |
41 |
Correct |
5 ms |
2996 KB |
Output is correct |
42 |
Correct |
7 ms |
2892 KB |
Output is correct |
43 |
Correct |
3 ms |
1832 KB |
Output is correct |
44 |
Correct |
3 ms |
2104 KB |
Output is correct |
45 |
Correct |
5 ms |
2960 KB |
Output is correct |
46 |
Correct |
5 ms |
2960 KB |
Output is correct |
47 |
Correct |
5 ms |
3016 KB |
Output is correct |
48 |
Correct |
5 ms |
3004 KB |
Output is correct |
49 |
Correct |
3 ms |
1868 KB |
Output is correct |
50 |
Correct |
5 ms |
3012 KB |
Output is correct |
51 |
Correct |
4 ms |
3020 KB |
Output is correct |
52 |
Correct |
4 ms |
2404 KB |
Output is correct |
53 |
Correct |
5 ms |
2900 KB |
Output is correct |
54 |
Correct |
3 ms |
3288 KB |
Output is correct |
55 |
Correct |
3 ms |
3296 KB |
Output is correct |
56 |
Correct |
3 ms |
3280 KB |
Output is correct |