Submission #591459

# Submission time Handle Problem Language Result Execution time Memory
591459 2022-07-07T12:51:36 Z piOOE JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    //j = 0, o = 1, i = 2
    vector<int> g[3];
    string s;
    cin >> s;
    int ans = n;
    for (int i = 0; i < n; ++i) {
        g[s[i] == 'J' ? 0 : s[i] == 'O' ? 1 : 2].push_back(i);
    }
    auto nxt = [&](int t, int i) {
        auto it = upper_bound(g[t].begin(), g[t].end(), i);
        if (g[t].end() - it < k) {
            return -1;
        } else {
            return *(it + k - 1);
        }
    };
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'J') {
            int x = i - 1;
            for (int t = 0; t < 3; ++t) {
                x = nxt(t, x);
                if (x == -1) {
                    break;
                }
            }
            if (x != -1) {
                ans = min(ans, i + (n - x - 1));
            }
        }
    }
    cout << (ans == n ? -1 : ans);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -