Submission #365331

# Submission time Handle Problem Language Result Execution time Memory
365331 2021-02-11T13:26:17 Z AdOjis485 JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
13 ms 3316 KB
#include <iostream>
#include <vector>
#include <algorithm>
#define int int64_t
using namespace std;

signed main()
{
    int n, k;
    string s;
    cin >> n >> k >> s;
    
    vector<int> jvec;
    vector<int> ovec;
    vector<int> ivec;

    for(int i = 0; i < n; i ++) 
    {
        if(s[i] == 'J') jvec.push_back(i);
        else if(s[i] == 'O') ovec.push_back(i);
        else ivec.push_back(i);
    }

    int ans = 1e9;
    int j = 0;
    int j2 = 0;

    for(int i = 0; i + k <= jvec.size(); i ++)
    {
        while(j < ovec.size() && ovec[j] < jvec[i + k - 1]) j ++;
        if(j + k > ovec.size()) continue;
        while(j2 < ivec.size() && ivec[j2] < ovec[j + k - 1]) j2 ++;
        if(j2 + k <= ivec.size())
        {
         //   cerr << i << " " << j << " " << j2 << " " << j2 + k - 4 - i << '\n'; 
            ans = min(ivec[j2 + k - 1] - jvec[i] - 3 * k + 1, ans);
        }
    }

    if(ans == 1e9) cout << "-1\n";
    else cout << ans << '\n';    
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:28:26: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i = 0; i + k <= jvec.size(); i ++)
      |                    ~~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:30:17: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         while(j < ovec.size() && ovec[j] < jvec[i + k - 1]) j ++;
      |               ~~^~~~~~~~~~~~~
ho_t2.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         if(j + k > ovec.size()) continue;
      |            ~~~~~~^~~~~~~~~~~~~
ho_t2.cpp:32:18: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         while(j2 < ivec.size() && ivec[j2] < ovec[j + k - 1]) j2 ++;
      |               ~~~^~~~~~~~~~~~~
ho_t2.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         if(j2 + k <= ivec.size())
      |            ~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 500 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 500 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 9 ms 2272 KB Output is correct
37 Correct 10 ms 2664 KB Output is correct
38 Correct 11 ms 2892 KB Output is correct
39 Correct 10 ms 3004 KB Output is correct
40 Correct 10 ms 3048 KB Output is correct
41 Correct 13 ms 3048 KB Output is correct
42 Correct 11 ms 2920 KB Output is correct
43 Correct 6 ms 2036 KB Output is correct
44 Correct 7 ms 2156 KB Output is correct
45 Correct 10 ms 2988 KB Output is correct
46 Correct 12 ms 3112 KB Output is correct
47 Correct 10 ms 2924 KB Output is correct
48 Correct 10 ms 3016 KB Output is correct
49 Correct 7 ms 1896 KB Output is correct
50 Correct 10 ms 3020 KB Output is correct
51 Correct 10 ms 2920 KB Output is correct
52 Correct 8 ms 2396 KB Output is correct
53 Correct 9 ms 2912 KB Output is correct
54 Correct 8 ms 3316 KB Output is correct
55 Correct 8 ms 3316 KB Output is correct
56 Correct 8 ms 3316 KB Output is correct