제출 #779600

#제출 시각아이디문제언어결과실행 시간메모리
7796001binJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
26 ms3484 KiB
#include <bits/stdc++.h>

using namespace std;

#define all(v) v.begin(), v.end()
typedef long long ll;
int n, k, p[3][200005], ans;
string s, t = "JOI";
int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> k >> s;
    for(int j = 1; j <= n; j++){
        for(int i = 0; i < 3; i++) p[i][j] = p[i][j - 1];
        for(int i = 0; i < 3; i++)
            if(s[j - 1] == t[i]) p[i][j]++;
    }
    p[0][n + 1] = p[1][n + 1] = p[2][n + 1] = 1e9;
    ans = n + 1;
    for(int s = 0; s < n; s++){
        int x = s, cnt = 0;
        for(int i = 0; i < 3; i++){
            cnt = p[i][x] + k;
            x = lower_bound(p[i], p[i] + n + 2, cnt) - p[i];
            if(x == n + 1) break;
        }
        cout << '\n';
        if(x <= n) ans = min(ans, x - s - 3 * k);
    }
    cout << (ans == n + 1 ? -1 : ans);
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...