#include <bits/stdc++.h>
using namespace std;
#define int long long
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);
#define OYY 1000000005
#define mod 998244353
#define mid (start+end)/2
vector <pair<int,int>> v;
int dizi[200005],tree[800005];
void build(int node,int start,int end){
if(start==end){
tree[node]=dizi[start];
return ;
}
build(node*2,start,mid),build(node*2+1,mid+1,end);
tree[node]=tree[node*2]+tree[node*2+1];
}
int query(int node,int start,int end,int l,int r){
if(start>end || start>r || end<l)return 0;
if(start>=l&& end<=r)return tree[node];
return query(node*2,start,mid,l,r)+query(node*2+1,mid+1,end,l,r);
}
int32_t main(){
faster
int n,k;cin>>n>>k;
string s,a;cin>>a;
s="$";
s+=a;
int say=0;
int tut=0;
char c='J',l='$';
int o=-1;
for(int i=1;i<=n;i++){
if(s[i]==c){
if(o==-1)o=i;
dizi[i]=1;
tut++;
}
if(s[i]==l){
dizi[i]=1;
}
if(tut==k){
//tut=0;
c='O';
l='J';
}
else if(tut==2*k){
c='I';
l='$';
}
else if(tut==3*k){
v.push_back({o,i});
o=-1;
tut=0;
c='J';
// l='$';
}
}
build(1,1,n);
int cev=OYY;
for(int i=0;i<v.size();i++){
int a=v[i].first;
int b=v[i].second;
//for(int j=a;j<=b;j++)cout<<dizi[j]<<" ";
int deg=query(1,1,n,a,b);
if(deg>=3*k){
deg=(b-a)-deg+1;
cev=min(deg,cev);
}
}
if(cev!=OYY)cout<<cev<<'\n';
else cout<<-1<<'\n';
return 0;
}
Compilation message
ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:65:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
ho_t2.cpp:33:9: warning: unused variable 'say' [-Wunused-variable]
33 | int say=0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |