Submission #958382

# Submission time Handle Problem Language Result Execution time Memory
958382 2024-04-05T16:53:24 Z JwFXoiz JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
8 ms 3344 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define inf 0x3F3F3F3F

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, K;
    cin >> n >> K;
    string s;
    cin >> s;
    vector<int> v[3];
    for (int i = 0; i < n; i++) v[(s[i] == 'O') + (s[i] == 'I') * 2].push_back(i);
    int ans = inf;
    for (int i = 0; i + K <= v[0].size(); i++)
    {
        auto it = lower_bound(v[1].begin(), v[1].end(), v[0][i + K - 1]);
        if (it == v[1].end()) break;
        int j = it - v[1].begin();
        if (j + K > v[1].size()) break;
        it = lower_bound(v[2].begin(), v[2].end(), v[1][j + K - 1]);
        if (it == v[2].end()) break;
        int k = it - v[2].begin();
        if (k + K > v[2].size()) break;
        ans = min(ans, (v[2][k + K - 1] - v[0][i] + 1) - 3 * K);
    }
    cout << (ans >= inf ? -1 : ans) << '\n';
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:19:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0; i + K <= v[0].size(); i++)
      |                     ~~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:24:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         if (j + K > v[1].size()) break;
      |             ~~~~~~^~~~~~~~~~~~~
ho_t2.cpp:28:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         if (k + K > v[2].size()) break;
      |             ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 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 452 KB Output is correct
8 Correct 0 ms 456 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 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 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 452 KB Output is correct
8 Correct 0 ms 456 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 1 ms 460 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 456 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 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 456 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 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 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 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 452 KB Output is correct
8 Correct 0 ms 456 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 1 ms 460 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 456 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 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 456 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 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 460 KB Output is correct
36 Correct 8 ms 2388 KB Output is correct
37 Correct 8 ms 3024 KB Output is correct
38 Correct 8 ms 2860 KB Output is correct
39 Correct 7 ms 2984 KB Output is correct
40 Correct 4 ms 3028 KB Output is correct
41 Correct 6 ms 3028 KB Output is correct
42 Correct 8 ms 3024 KB Output is correct
43 Correct 2 ms 1968 KB Output is correct
44 Correct 2 ms 2132 KB Output is correct
45 Correct 3 ms 2968 KB Output is correct
46 Correct 3 ms 2968 KB Output is correct
47 Correct 3 ms 3148 KB Output is correct
48 Correct 3 ms 3024 KB Output is correct
49 Correct 2 ms 2004 KB Output is correct
50 Correct 3 ms 3000 KB Output is correct
51 Correct 3 ms 3152 KB Output is correct
52 Correct 2 ms 2700 KB Output is correct
53 Correct 3 ms 2896 KB Output is correct
54 Correct 4 ms 3292 KB Output is correct
55 Correct 4 ms 3344 KB Output is correct
56 Correct 4 ms 3296 KB Output is correct