답안 #936699

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936699 2024-03-02T14:44:18 Z kitlix JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
25 ms 7396 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int INF = 1e9;

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<vector<int>> pref(3, vector<int>(n));
    for (int i = 0; i < n; ++i) {
        if (i)
            for (int j = 0; j < 3; ++j)
                pref[j][i] = pref[j][i - 1];
        if (s[i] == 'J')
            pref[0][i] += 1;
        else if (s[i] == 'O')
            pref[1][i] += 1;
        else
            pref[2][i] += 1;
    }
    int ans = INF;
    for (int i = 0; i + 3 * k <= n; ++i) {
        int needid = i;
        for (int j = 0; j < 3; ++j) {
            int prval = (needid ? pref[j][needid - 1] : 0);
            int curid = lower_bound(pref[j].begin(), pref[j].end(), prval + k) - pref[j].begin();
            needid = max(needid, curid);
        }
        if (needid < n)
            ans = min(ans, (needid - i + 1) - 3 * k);
    }
    cout << (ans == INF ? -1 : ans);
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 424 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 424 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 456 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 424 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 456 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 456 KB Output is correct
36 Correct 21 ms 6628 KB Output is correct
37 Correct 23 ms 7140 KB Output is correct
38 Correct 24 ms 7144 KB Output is correct
39 Correct 23 ms 7192 KB Output is correct
40 Correct 17 ms 7144 KB Output is correct
41 Correct 24 ms 7144 KB Output is correct
42 Correct 25 ms 7276 KB Output is correct
43 Correct 9 ms 4700 KB Output is correct
44 Correct 12 ms 5724 KB Output is correct
45 Correct 17 ms 7140 KB Output is correct
46 Correct 15 ms 7132 KB Output is correct
47 Correct 15 ms 7160 KB Output is correct
48 Correct 14 ms 7144 KB Output is correct
49 Correct 10 ms 4840 KB Output is correct
50 Correct 15 ms 7144 KB Output is correct
51 Correct 15 ms 7144 KB Output is correct
52 Correct 6 ms 6888 KB Output is correct
53 Correct 7 ms 7140 KB Output is correct
54 Correct 17 ms 7396 KB Output is correct
55 Correct 9 ms 7140 KB Output is correct
56 Correct 4 ms 7144 KB Output is correct