제출 #254877

#제출 시각아이디문제언어결과실행 시간메모리
254877imeimi2000JJOOII 2 (JOI20_ho_t2)C++17
100 / 100
33 ms2044 KiB
#include <bits/stdc++.h>

using namespace std;

int n, k;
char S[200002];
vector<int> P[4];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k >> S + 1;
    for (int i = 1; i <= n; ++i) {
        P[S[i] == 'J' ? 1 : S[i] == 'O' ? 2 : 3].push_back(i);
    }
    int ans = n + 1;
    for (int s = 1; s <= n; ++s) {
        int e = s;
        for (int i = 1; i <= 3; ++i) {
            auto it = lower_bound(P[i].begin(), P[i].end(), e);
            if (int(P[i].end() - it) < k) {
                e = 10 * n;
                break;
            }
            e = *(it + (k - 1));
        }
        ans = min(ans, (e - s + 1) - 3 * k);
    }
    printf("%d\n", ans > n ? -1 : ans);
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:10:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     cin >> n >> k >> S + 1;
                      ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...