답안 #365380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
365380 2021-02-11T14:35:27 Z Aderfish JJOOII 2 (JOI20_ho_t2) C++17
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";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -