Submission #423373

# Submission time Handle Problem Language Result Execution time Memory
423373 2021-06-11T03:53:31 Z tengiz05 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
185 ms 3672 KB
#include <bits/stdc++.h>
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, k;
    std::cin >> n >> k;
    std::string s;
    std::cin >> s;
    std::vector<std::vector<int>> pr(3, std::vector<int>(n + 1));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            pr[j][i + 1] = pr[j][i] + (std::string("JOI").find(s[i]) == j);
        }
    }
    int ans = n + 1;
    for (int i = k; i <= n - 2 * k; i++) {
        if (pr[0][i] < k || pr[1][n] - pr[1][i] < k) {
            continue;
        }
        auto check = [&](int j) {
            if (pr[1][j] - pr[1][i] < k) {
                return -1;
            }
            int l = j, r = n + 1;
            while (l + 1 < r) {
                int mid = (l + r) / 2;
                if (pr[2][mid] - pr[2][j] >= k) {
                    r = mid;
                } else {
                    l = mid;
                }
            }
            if (r <= n) {
                return r;
            }
            return -2;
        };
        int l = i, r = n + 1;
        while (l + 1 < r) {
            int mid = (l + r) / 2;
            if (~check(mid)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        if (r <= n) {
            r = check(r);
            int L = 0, R = i + 1;
            while (L + 1 < R) {
                int mid = (L + R) / 2;
                if (pr[0][i] - pr[0][mid - 1] >= k) {
                    L = mid;
                } else {
                    R = mid;
                }
            }
            if (r > 0)
                ans = std::min(ans, r - L + 1 - 3 * k);
        }
    }
    if (ans > n) {
        std::cout << -1 << "\n";
    } else {
        std::cout << ans << "\n";
    }
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:12:70: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   12 |             pr[j][i + 1] = pr[j][i] + (std::string("JOI").find(s[i]) == j);
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 360 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 360 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 147 ms 3544 KB Output is correct
37 Correct 181 ms 3672 KB Output is correct
38 Correct 185 ms 3672 KB Output is correct
39 Correct 148 ms 3672 KB Output is correct
40 Correct 73 ms 3672 KB Output is correct
41 Correct 122 ms 3672 KB Output is correct
42 Correct 174 ms 3672 KB Output is correct
43 Correct 31 ms 2508 KB Output is correct
44 Correct 39 ms 3032 KB Output is correct
45 Correct 52 ms 3672 KB Output is correct
46 Correct 63 ms 3672 KB Output is correct
47 Correct 51 ms 3672 KB Output is correct
48 Correct 52 ms 3672 KB Output is correct
49 Correct 35 ms 2648 KB Output is correct
50 Correct 51 ms 3672 KB Output is correct
51 Correct 51 ms 3672 KB Output is correct
52 Correct 11 ms 3544 KB Output is correct
53 Correct 13 ms 3672 KB Output is correct
54 Correct 172 ms 3672 KB Output is correct
55 Correct 43 ms 3672 KB Output is correct
56 Correct 12 ms 3672 KB Output is correct