Submission #753912

# Submission time Handle Problem Language Result Execution time Memory
753912 2023-06-06T09:58:31 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
33 ms 3300 KB
/*
isl gae
e
*/
#include <bits/stdc++.h>
#include <sstream>
#define ll                  long long
#define lp(a,b)             for(ll i = a; i<b; i++)
#define pl(a,b)             for(ll i = a;i>=b;i--)
using namespace std;
int main()
{  
    ll n,k;cin >> n >> k;string s;cin >> s;vector <ll> v[3];
    lp(0,n){
        v[(s[i] == 'J' ? 0 : (s[i] == 'O' ? 1 : 2))].push_back(i);
    }
    ll pt = 0,it = 0;
    string kx = string(k, 'J') + string(k, 'O') + string(k, 'I');
    while(pt < n && it < kx.size()){
        if(s[pt] == kx[it]){
            it++;
        }
        pt++;
    }
    if(it < k * 3){
        cout << -1 << char(012);exit(0);
    }
    ll mn = 1e9;
    lp(k * 3 - 1,n){
        if(v[0][0] > i || v[1][0] > i || v[2][0] > i){
            continue;
        }
        ll rx = --upper_bound(v[2].begin(), v[2].end(), i) - v[2].begin();
        ll lx = rx - k + 1;
        if(lx < 0){
            continue;
        }
        ll rxx = v[2][rx];
        ll lxx = v[2][lx];
        if(v[1][0] > lxx){
            continue;
        }
        ll rx2 = --upper_bound(v[1].begin(), v[1].end(), lxx) - v[1].begin();
        ll lx2 = rx2 - k + 1;
        if(lx2 < 0){
            continue;
        }
        ll rxx2 = v[1][rx2];
        ll lxx2 = v[1][lx2];
        if(v[0][0] > lxx2){
            continue;
        }
        ll rx3 = --upper_bound(v[0].begin(), v[0].end(), lxx2) - v[0].begin();
        ll lx3 = rx3 - k + 1;
        if(lx3 < 0){
            continue;
        }
        ll rxx3 = v[0][rx3];
        ll lxx3 = v[0][lx3];
        mn = min(mn, ((rxx - lxx3 + 1) - k * 3));
    }
    cout << mn << char(012);
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:19:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     while(pt < n && it < kx.size()){
      |                     ~~~^~~~~~~~~~~
ho_t2.cpp:48:12: warning: unused variable 'rxx2' [-Wunused-variable]
   48 |         ll rxx2 = v[1][rx2];
      |            ^~~~
ho_t2.cpp:58:12: warning: unused variable 'rxx3' [-Wunused-variable]
   58 |         ll rxx3 = v[0][rx3];
      |            ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 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 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 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 1 ms 340 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 340 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 300 KB Output is correct
25 Correct 1 ms 300 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 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 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 1 ms 340 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 340 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 300 KB Output is correct
25 Correct 1 ms 300 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 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 300 KB Output is correct
36 Correct 28 ms 2404 KB Output is correct
37 Correct 33 ms 2892 KB Output is correct
38 Correct 27 ms 2868 KB Output is correct
39 Correct 27 ms 2836 KB Output is correct
40 Correct 22 ms 2892 KB Output is correct
41 Correct 28 ms 2968 KB Output is correct
42 Correct 27 ms 2888 KB Output is correct
43 Correct 12 ms 1852 KB Output is correct
44 Correct 17 ms 1856 KB Output is correct
45 Correct 21 ms 2972 KB Output is correct
46 Correct 21 ms 2936 KB Output is correct
47 Correct 19 ms 3020 KB Output is correct
48 Correct 21 ms 3008 KB Output is correct
49 Correct 6 ms 1836 KB Output is correct
50 Correct 8 ms 2964 KB Output is correct
51 Correct 8 ms 3020 KB Output is correct
52 Correct 8 ms 2628 KB Output is correct
53 Correct 8 ms 2888 KB Output is correct
54 Correct 13 ms 3292 KB Output is correct
55 Correct 11 ms 3292 KB Output is correct
56 Correct 7 ms 3300 KB Output is correct