답안 #1092995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092995 2024-09-25T16:06:23 Z ortsac JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
32 ms 3308 KB
#include <bits/stdc++.h>

using namespace std;

string w = "JOI";
int n, k;
string s;
vector<array<int, 3>> pf;

int pTem(int start, int b) {
    int l = start, r = n, ans = n + 1;
    while (l <= r) {
        int m = (l+r)/2;
        int qtd = (pf[m][b] - pf[start - 1][b]);
        if (qtd >= k) {
            ans = m;
            r = m - 1;
        } else {
            l = m + 1;
        }
    }
    return ans;
}

int INF = 0x3f3f3f3f;

int32_t main() {
    //freopen("in", "r", stdin);
    cin >> n >> k >> s;
    pf.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        pf[i] = pf[i - 1];
        for (int j = 0; j < 3; j++) {
            if (s[i - 1] == w[j]) pf[i][j]++;
        }
    }
    int ans = INF;
    for (int i = 1; i <= n; i++) {
        int a = pTem(i, 0);
        int b = pTem(a, 1);
        int c = pTem(b, 2);
        if (c == (n + 1)) continue;
        ans = min(ans, c - i + 1 - 3*k);
    }
    if (ans == INF) cout << "-1\n";
    else cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 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 428 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 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 428 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 344 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 348 KB Output is correct
21 Correct 1 ms 372 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 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 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 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 428 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 344 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 348 KB Output is correct
21 Correct 1 ms 372 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 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 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 28 ms 3048 KB Output is correct
37 Correct 29 ms 3308 KB Output is correct
38 Correct 29 ms 3304 KB Output is correct
39 Correct 28 ms 3052 KB Output is correct
40 Correct 22 ms 3308 KB Output is correct
41 Correct 27 ms 3308 KB Output is correct
42 Correct 32 ms 3308 KB Output is correct
43 Correct 13 ms 2028 KB Output is correct
44 Correct 15 ms 2696 KB Output is correct
45 Correct 19 ms 3052 KB Output is correct
46 Correct 20 ms 3052 KB Output is correct
47 Correct 20 ms 3308 KB Output is correct
48 Correct 20 ms 3308 KB Output is correct
49 Correct 14 ms 2280 KB Output is correct
50 Correct 20 ms 3296 KB Output is correct
51 Correct 21 ms 3304 KB Output is correct
52 Correct 12 ms 3052 KB Output is correct
53 Correct 13 ms 3308 KB Output is correct
54 Correct 16 ms 3304 KB Output is correct
55 Correct 13 ms 3308 KB Output is correct
56 Correct 13 ms 3308 KB Output is correct