제출 #1319333

#제출 시각아이디문제언어결과실행 시간메모리
1319333khanhphucscratchJJOOII 2 (JOI20_ho_t2)C++20
100 / 100
19 ms1796 KiB
#include<bits/stdc++.h>
using namespace std;
vector<int> place[3];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k; string s; cin>>n>>k>>s;
    for(int i = 0; i < n; i++){
        if(s[i] == 'J') place[0].push_back(i);
        if(s[i] == 'O') place[1].push_back(i);
        if(s[i] == 'I') place[2].push_back(i);
    }
    int ans = 1e9;
    for(int i = 0; i < n; i++){
        int p = i;
        bool ok = 1;
        for(int j = 0; j <= 2; j++){
            p = lower_bound(place[j].begin(), place[j].end(), p) - place[j].begin() + k - 1;
            if(p >= place[j].size()){ok = 0; break;}
            p = place[j][p] + 1;
        }
        if(ok == 1) ans = min(ans, p-i-3*k);
    }
    if(ans <= n) cout<<ans;
    else cout<<-1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...