제출 #1354968

#제출 시각아이디문제언어결과실행 시간메모리
1354968kismisJJOOII 2 (JOI20_ho_t2)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vt vector 
#define pb push_back
#define pob pop_back
#define endl '\n'
#define fi first
#define se second

signed main() {
    int n , k;
    cin >> n >> k;
    string s;
    cin >> s;
    vt<int> J(n , 0);
    vt<int> O(n , 0);
    vt<int> I(n , 0);
    vt<int> j;
    for(int i=0 ; i<n ; i++){
        if(s[i] == 'J')
        j.pb(i);
    }
    J[0] += (s[0] == 'J');
    O[0] += (s[0] == 'O');
    I[0] += (s[0] == 'I');
    for(int i=1 ; i<n ; i++){
        J[i] = J[i-1] + (s[i] == 'J');
        O[i] = O[i-1] + (s[i] == 'O');
        I[i] = I[i-1] + (s[i] == 'I');
    }
    int ans = LLONG_MAX;
    for(int i=0 ; i<j.size() ; i++){
        int xx = k; 
        int yy;
        int zz;
        int e;
        if(i !=0)
        xx += J[i-1];
    if(lower_bound(J.begin() , J.end() , xx) != J.end())
     yy = lower_bound(J.begin() , J.end() , xx) - J.begin();
else continue;
    yy = O[yy] + k;
    if(lower_bound(O.begin() , O.end() , yy) != O.end())
     zz = lower_bound(O.begin() , O.end() , yy) - O.begin();
   else continue;
   zz = I[zz] + k;
   if(lower_bound(I.begin() , I.end() , zz) != I.end())
    e = lower_bound(I.begin() , I.end() , zz) - I.begin();
else continue;
int end = e - i + 1;
end -= 3*k;
ans = min(ans , end);
    }
    if(ans == LLONG_MAX)
    cout << -1 << endl;
else
cout << ans << endl;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…