제출 #1234122

#제출 시각아이디문제언어결과실행 시간메모리
1234122marJJOOII 2 (JOI20_ho_t2)C++20
13 / 100
2094 ms608 KiB
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;

int main() {
    int n, k;
    cin >> n >> k;
    
    vector<char> s(n+2), tmp(3*k + 2);

    for(int i = 1; i <= n; ++i) {
        cin >> s[i];
    }

    for(int i = 0; i < 3*k; i++) {
        if (i / k == 0) tmp[i + 1] = 'J';
        else if (i / k == 1) tmp[i + 1] = 'O';
        else tmp[i + 1] = 'I';
    }

    int res = inf;

    for(int i = 1; i <= n; i++){
        int pos = i;

        for(int j = 1; j <= 3*k; j++) {
            while (pos <= n + 1 && s[pos] != tmp[j]) pos++;
            pos++;
        }
        pos--; 
        if(pos <= n) res = min(res, pos - i + 1 - 3 * k);
    }

    if(res == inf) cout << "-1\n";
    else cout << res <<endl;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...