Submission #594028

# Submission time Handle Problem Language Result Execution time Memory
594028 2022-07-11T22:48:58 Z stevancv JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
5 ms 2536 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 2e5 + 2;
const int mod = 1e9 + 7;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    string s; cin >> s;
    vector<int> a, b;
    vector<int> pref(n);
    for (int i = 0; i < n; i++) {
        if (i > 0) pref[i] += pref[i - 1];
        if (s[i] == 'J') a.push_back(i);
        if (s[i] == 'O') pref[i]++;
        if (s[i] == 'I') b.push_back(i);
    }
    auto Get = [&] (int l, int r) {
        if (l > r) return 0;
        int o = pref[r];
        if (l > 0) o -= pref[l - 1];
    };
    int ans = 1e9;
    int j = 0;
    for (int i = k - 1; i < a.size(); i++) {
        while (j < b.size() && pref[b[j]] - pref[a[i]] < k) j++;
        if (j == b.size()) continue;
        if (pref[b[j]] - pref[a[i]] >= k && b.size() - j >= k) smin(ans, b[j + k - 1] - a[i - k + 1] + 1 - 3 * k);
    }
    if (ans == 1e9) ans = -1;
    cout << ans << en;
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:33:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i = k - 1; i < a.size(); i++) {
      |                         ~~^~~~~~~~~~
ho_t2.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         while (j < b.size() && pref[b[j]] - pref[a[i]] < k) j++;
      |                ~~^~~~~~~~~~
ho_t2.cpp:35:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         if (j == b.size()) continue;
      |             ~~^~~~~~~~~~~
ho_t2.cpp:36:58: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |         if (pref[b[j]] - pref[a[i]] >= k && b.size() - j >= k) smin(ans, b[j + k - 1] - a[i - k + 1] + 1 - 3 * k);
      |                                             ~~~~~~~~~~~~~^~~~
ho_t2.cpp:26:10: warning: variable 'Get' set but not used [-Wunused-but-set-variable]
   26 |     auto Get = [&] (int l, int r) {
      |          ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 316 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 320 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 316 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 320 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 4 ms 2048 KB Output is correct
37 Correct 5 ms 2420 KB Output is correct
38 Correct 5 ms 2396 KB Output is correct
39 Correct 5 ms 2512 KB Output is correct
40 Correct 5 ms 2388 KB Output is correct
41 Correct 5 ms 2404 KB Output is correct
42 Correct 5 ms 2344 KB Output is correct
43 Correct 3 ms 1620 KB Output is correct
44 Correct 3 ms 1884 KB Output is correct
45 Correct 5 ms 2344 KB Output is correct
46 Correct 5 ms 2504 KB Output is correct
47 Correct 5 ms 2344 KB Output is correct
48 Correct 5 ms 2524 KB Output is correct
49 Correct 3 ms 1624 KB Output is correct
50 Correct 5 ms 2536 KB Output is correct
51 Correct 5 ms 2312 KB Output is correct
52 Correct 5 ms 2096 KB Output is correct
53 Correct 5 ms 2496 KB Output is correct
54 Correct 3 ms 2512 KB Output is correct
55 Correct 4 ms 2520 KB Output is correct
56 Correct 3 ms 2512 KB Output is correct