제출 #1287364

#제출 시각아이디문제언어결과실행 시간메모리
1287364peanutJJOOII 2 (JOI20_ho_t2)C++20
0 / 100
1 ms568 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int n, k; cin >> n >> k;
    string s; cin >> s;

    int st = -1, ed = -1;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'J' && st == -1) st = i;
        if (s[i] == 'I') ed = i;
    }

    int ops = 0;
    int cntJ = 0, cntO = 0, cntI = 0;
    for (int i = st; i <= ed; ++i)
    {
        if (cntJ < k) {
            if (s[i] != 'J') ops++;
            else cntJ++;
        }
        else if (cntJ == k && cntO < k) {
            if (s[i] != 'O') ops++;
            else cntO++;
        }
        else if (cntJ == k && cntO == k && cntI < k) {
            if (s[i] != 'I') ops++;
            else cntI++;
        }
    }
    if (cntJ < k || cntO < k || cntI < k) cout << -1;
    else cout << ops;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...