Submission #583937

#TimeUsernameProblemLanguageResultExecution timeMemory
583937forelaxJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
10 ms612 KiB
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    int pb = -1, pj = 0, po = 0, pi = 0;
    int co = 0, cj = 0, ci = 0, rez = -1;
    for (;pb < n;pb++) {
        if (pb >= 0) {
            if (s[pb] == 'J')cj--;
        }
        for (;pj < n && cj < k;pj++) {
            if (s[pj] == 'J')cj++;
            if (s[pj] == 'O')co--;
            for (;po < n && co < k;po++) {
                if (s[po] == 'O')co++;
                if (s[po] == 'I')ci--;
                for (;pi < n && ci < k;pi++) {
                    if (s[pi] == 'I')ci++;

                }
            }
        }
        if (cj != k || co != k || ci != k)break;
        int nrez = pi - pb - 1 - 3 * k;
        if (rez == -1)rez = nrez;
        rez = min(rez, nrez);
    }
    cout << rez;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...