Submission #1343217

#TimeUsernameProblemLanguageResultExecution timeMemory
1343217maxiedJJOOII 2 (JOI20_ho_t2)C++20
13 / 100
2094 ms720 KiB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int ans = INT_MAX;
    bool ok = false;
    for (int i = 0; i < n; i++){
        if (s[i] == 'J'){
            // start the joi here
            int need = k - 1;
            int waste = 0;
            int j = i + 1;
            while (j < n && need){
                need -= (s[j] == 'J');
                waste += (s[j] != 'J');
                j++;
            }
            if (need){
                continue;
            }
            need = k;
            while (j < n && need){
                need -= (s[j] == 'O');
                waste += (s[j] != 'O');
                j++;
            }
            if (need){
                continue;
            }
            need = k;
            while (j < n && need){
                need -= (s[j] == 'I');
                waste += (s[j] != 'I');
                j++;
            }
            if (need){
                continue;
            }
            ok = true;
            ans = min(ans, waste);
        }
    }
    if (!ok){
        cout << "-1" << '\n';
    }
    else{
        cout << ans << '\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...