Submission #781518

#TimeUsernameProblemLanguageResultExecution timeMemory
781518vjudge1JJOOII 2 (JOI20_ho_t2)C++17
13 / 100
2079 ms852 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define OYY 1000000000005
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mid (start+end)/2
#define mod 1000000007

int32_t main(){
    faster
    int n,k;cin>>n>>k;
    string s;cin>>s;
    int ger=OYY,cev=OYY;
    bool stop=false,pl=false,th=false;
    for(int i=0;i<n;i++){
        if(s[i]=='J'){
            cev=0;
            stop=false;
            pl=false;
            th=false;
            int j,tut=0;
            for(j=i;j<n;j++){
                if(s[j]=='J')tut++;
                else cev++;
                if(tut==k){
                    stop=true;
                    break;
                }
            }
            tut=0;
            j++;
           // cout<<j<<endl;
            for(;j<n && stop;j++){
                //cout<<s[j]<<" "<<tut<<endl;
                if(s[j]=='O')tut++;
                else cev++;
                if(tut==k){
                    pl=true;
                    break;
                }
            }
            tut=0;
            j++;
          //  cout<<j<<endl;
            for(;j<n && pl;j++){
                if(s[j]=='I')tut++;
                else cev++;
                if(tut==k){
                    th=true;
                    break;
                }
            }
            //cout<<stop<<" "<<pl<<" "<<th<<endl;

        }
        if(th)ger=min(ger,cev);
    }
    if(ger==OYY)ger=-1;
    cout<<ger<<'\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...