Submission #995261

# Submission time Handle Problem Language Result Execution time Memory
995261 2024-06-08T17:47:41 Z gmroh06 JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
6 ms 5028 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

inline void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

const ll INF = 1e16;

ll n, k, ans = INF;
vector<ll> a, b, v;
string s;

int main() {
    fastio();

    cin >> n >> k >> s;

    a.resize(n + 2);
    b.resize(n + 2);

    a[0] = b[n + 1] = -1;

    for (ll i = 1; i <= n; i++) {
        if (s[i - 1] == 'J') {
            v.emplace_back(i);
        }

        if (v.size() < k) {
            a[i] = -1;
        } else {
            a[i] = *(v.end() - k);
        }
    }

    v.clear();

    for (ll i = n; i > 0; i--) {
        if (s[i - 1] == 'I') {
            v.emplace_back(i);
        }

        if (v.size() < k) {
            b[i] = -1;
        } else {
            b[i] = *(v.end() - k);
        }
    }

    v.clear();

    for (ll i = 1; i <= n; i++) {
        if (s[i - 1] == 'O') {
            v.emplace_back(i);
        }

        if (v.size() < k) {
            continue;
        }

        ll l = a[*(v.end() - k) - 1], r = b[i + 1];

        if (l > -1 and r > -1) {
            ans = min(ans, r - l + 1);
        }
    }

    cout << (ans == INF ? -1 : ans - 3 * k);

    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:34:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   34 |         if (v.size() < k) {
      |             ~~~~~~~~~^~~
ho_t2.cpp:48:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   48 |         if (v.size() < k) {
      |             ~~~~~~~~~^~~
ho_t2.cpp:62:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   62 |         if (v.size() < k) {
      |             ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 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 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 0 ms 452 KB Output is correct
29 Correct 0 ms 452 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 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 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 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 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 0 ms 452 KB Output is correct
29 Correct 0 ms 452 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 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 0 ms 348 KB Output is correct
36 Correct 5 ms 4196 KB Output is correct
37 Correct 6 ms 5028 KB Output is correct
38 Correct 6 ms 4960 KB Output is correct
39 Correct 5 ms 4960 KB Output is correct
40 Correct 6 ms 4960 KB Output is correct
41 Correct 6 ms 4956 KB Output is correct
42 Correct 5 ms 4956 KB Output is correct
43 Correct 4 ms 3356 KB Output is correct
44 Correct 4 ms 3736 KB Output is correct
45 Correct 6 ms 4960 KB Output is correct
46 Correct 5 ms 4960 KB Output is correct
47 Correct 6 ms 4960 KB Output is correct
48 Correct 6 ms 4960 KB Output is correct
49 Correct 4 ms 3428 KB Output is correct
50 Correct 5 ms 4984 KB Output is correct
51 Correct 5 ms 4960 KB Output is correct
52 Correct 5 ms 4452 KB Output is correct
53 Correct 5 ms 4960 KB Output is correct
54 Correct 3 ms 4988 KB Output is correct
55 Correct 3 ms 4960 KB Output is correct
56 Correct 4 ms 4984 KB Output is correct