Submission #583932

# Submission time Handle Problem Language Result Execution time Memory
583932 2022-06-26T13:54:19 Z forelax JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
1 ms 212 KB
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s;
    int n;
    int K;
    cin >> n >> K;
    cin >> s;
    int rez = n;
    int j, k, l, cj = 0, co = 0, ci = 0;
    for (j = 0;j < n && cj < K;j++) {
        if (s[j] == 'J')cj++;
    }
    if (cj != K) {
        cout << -1;
        return 0;
    }
    for (k = j;k < n && co < K;k++) {
        if (s[k] == 'O')co++;
    }
    if (co != K) {
        cout << -1;
        return 0;
    }
    for (l = k;l < n && ci < K;l++) {
        if (s[l] == 'I')ci++;
    }
    if (ci != K) {
        cout << -1;
        return 0;
    }
    for (int i = 0; i < n; i++) {
        if (s[i] == 'J') {
            cj--;
            for (;j < n && cj < K;j++) {
                if (s[j] == 'J')cj++;
                if (s[j] == 'O')
                    for (;k < n && co < K;k++) {
                        if (s[k] == 'O')co++;
                        if (s[k] == 'I')
                            for (;l < n && ci < K;l++) {
                                if (s[l] == 'I')ci++;
                            }
                    }
            }
        }
        if (cj == K && co == K && ci == K) {
            rez = min(rez, l - i + 1 - 3 * K);
        }
    }
    cout << rez;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -