Submission #365271

# Submission time Handle Problem Language Result Execution time Memory
365271 2021-02-11T11:08:54 Z Aderfish JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
using namespace std;
#define int int64_t

signed main(){
    int n, k;
    string str;
    cin >> n >> k >> str;

    vector<int> j_pref(n+1, 0), o_pref(n+1, 0), i_pref(n+1, 0);
    for(int i = 0; i < n; i++){
        j_pref[i+1] = j_pref[i];
        o_pref[i+1] = o_pref[i];
        i_pref[i+1] = i_pref[i];
        
        if(str[i] == 'J') j_pref[i+1]++;
        else if(str[i] == 'O') o_pref[i+1]++;
        else i_pref[i+1]++;
    }

    int min_ops = 1e9;
    for(int i = 0; i < n; i++){
        if(str[i] == 'J'){
            int curr_ops = 0;
            
            int l = i;
            int r = n;
            while(r-l > 1){
                int m = (l+r)/2;
                if(j_pref[m] - j_pref[i] < k) l = m;
                else r = m;
            }

            if(j_pref[r] - j_pref[i] < k) continue;
            curr_ops += r - i - k;

            i = r;
            l = i;
            r = n;
            while(r-l > 1){
                int m = (l+r)/2;
                if(o_pref[m] - o_pref[i] < k) l = m;
                else r = m;
            }

            if(o_pref[r] - o_pref[i] < k) continue;
            curr_ops += r - i - k;

            i = r;
            l = i;
            r = n;
            while(r-l > 1){
                int m = (l+r)/2;
                if(i_pref[m] - i_pref[i] < k) l = m;
                else r = m;
            }
            

            if(i_pref[r] - i_pref[i] < k) continue;
            curr_ops += r - i - k;

            min_ops = min(min_ops, curr_ops);
        }
    }

    if(min_ops == 1e9) cout << -1 << "\n";
    else cout << min_ops << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -