Submission #1115171

# Submission time Handle Problem Language Result Execution time Memory
1115171 2024-11-20T08:10:15 Z staszic_ojuz JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 336 KB
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n, k; cin >> n >> k;
    string s; cin >> s;
    if(s.find_first_of('J') > s.find_last_of('I')) {
        cout << -1;
        return 0;
    }

    s = s.substr(s.find_first_of('J'), s.find_last_of('I') - s.find_first_of('J') + 1);
    n = s.size();
    ll mn = 1e10;
    for(int i = 0; i < n; i++) {
        char c = s[i];
        if(c != 'J') continue;
        ll ileo = 0, ilej = 1, ilei = 0, usu = 0;
        for(int j = i+1; j < n; j++) {
            char z = s[j];
            if(z == 'O') {
                if(ileo < k) {
                    ilei = 0;
                    ileo++;
                } else {
                    usu++;
                }
            }
            if(z == 'J') {
                if(ilej < k) {
                    ileo = 0;
                    ilei = 0;
                    ilej++;
                } else {
                    usu++;
                }
            }
            if(z == 'I') {
                if(ilei + 1 >= k && ilej >= k && ileo >= k) {
                    ilei++;
                    break;
                } else {
                    ilei++;
                }
            }
        }
        if(ilei >= k && ileo >= k && ilej >= k) {
            mn = min(usu, mn);
        }
    }
    cout << (mn <= 2e8 ? mn : -1);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -