Submission #1086499

# Submission time Handle Problem Language Result Execution time Memory
1086499 2024-09-10T19:12:22 Z toast12 JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int j = 0, o = 0, i = 0;
    for (int idx = 0; idx < n; idx++) {
        if (s[idx] == 'J' && j < k) j++;
        else if (s[idx] == 'O' && j == k && o < k) o++;
        else if (s[idx] == 'I' && j == k && o == k && i < k) i++;
    }
    if (j != k || o != k || i != k) {
        cout << "-1\n";
        return 0;
    }
    int ans1 = 0;
    j = 0, o = 0, i = 0;
    for (int idx = 0; idx < n; idx++) {
        if (j == k && o == k && i == k) break;
        if (s[idx] == 'J' && j < k) j++;
        else if (s[idx] == 'O' && j == k && o < k) o++;
        else if (s[idx] == 'I' && j == k && o == k && i < k) i++;
        else {
            if (j || o || i)
                ans1++;
        }
    }
    int ans2 = 0;
    j = 0, o = 0, i = 0;
    for (int idx = n-1; idx >= 0; idx--) {
        if (j == k && o == k && i == k) break;
        if (s[idx] == 'I' && i < k) i++;
        else if (s[idx] == 'O' && i == k && o < k) o++;
        else if (s[idx] == 'J' && i == k && o == k && j < k) j++;
        else {
            if (j || o || i)
                ans2++;
        }
    }
    cout << min(ans1, ans2) << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -