Submission #669226

# Submission time Handle Problem Language Result Execution time Memory
669226 2022-12-06T04:07:09 Z GrandTiger1729 JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 320 KB
#include <iostream>
using namespace std;

int val(char c){
    if (c == 'J') return 0;
    if (c == 'O') return 1;
    if (c == 'I') return 2;
}

const int INF = 1e9 + 9;
int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n, k; cin >> n >> k;
    string s; cin >> s;
    int l[3]{}, r[3]{}, cnt[3]{};
    int ans = INF;
    while (r[2] < n){
        while (r[0] < n && cnt[0] < k){
            if (val(s[r[0]++]) == 0)
                cnt[0]++;
        }
        while (l[1] < r[0]){
            if (val(s[l[1]++]) == 1)
                cnt[1]--;
        }
        while (r[1] < n && cnt[1] < k){
            if (val(s[r[1]++]) == 1)
                cnt[1]++;
        }
        while (l[2] < r[1]){
            if (val(s[l[2]++]) == 2)
                cnt[2]--;
        }
        while (r[2] < n && cnt[2] < k){
            if (val(s[r[2]++]) == 2)
                cnt[2]++;
        }
        if (cnt[0] < k || cnt[1] < k || cnt[2] < k) break;
        ans = min(ans, r[2] - l[0] - 3 * k);
        if (val(s[l[0]++]) == 0)
            cnt[0]--;
    }
    cout << (ans == INF? -1: ans);
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int val(char)':
ho_t2.cpp:8:1: warning: control reaches end of non-void function [-Wreturn-type]
    8 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -