Submission #1341835

#TimeUsernameProblemLanguageResultExecution timeMemory
1341835cansu_mutluJJOOII 2 (JOI20_ho_t2)C++20
13 / 100
2094 ms752 KiB
#include<bits/stdc++.h>
#define int long long 
using namespace std;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin >> n >> k;
    string a,s;
    cin >> s;
    
    int ans = 1e18;
    for(int r = n-1;r>=0;r--)
    {
        char cur = 'I';
        int l = r;
        int ok = 0;
        int cnt = 0;
        queue<int> j,o,i;
        for(;l>=0;l--)
        {
        if(s[l]==cur)
        {
           
            cnt++;
            if(cnt==k)
            {
                if(cur=='J')
                {
                    ok = 1;
                    break;

                }
                else if(cur=='O') cur = 'J';
                else cur = 'O';
                cnt = 0;
            }
        }
        
        }
    if(ok) ans = min(ans,r-l+1);
    }
    if(ans==1e18) cout << -1 << endl;
    else cout << ans-(3*k) << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...