Submission #386097

# Submission time Handle Problem Language Result Execution time Memory
386097 2021-04-05T15:40:48 Z strawberry2005 JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
16 ms 3312 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long
const int mod = 1e9+7;
#define deb(x) cout<<#x<<": "<<x<<endl

int iceil(int a, int b) {
  return (a + b - 1) / b;
}
signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);

    #ifdef strawberryshaker2005
        freopen("input.txt", "r", stdin);
    #endif

    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    vector<int> J,O,I;
    for(int i=0;i<n;i++){
        if(s[i]=='J') J.push_back(i);
        if(s[i]=='O') O.push_back(i);
        if(s[i]=='I') I.push_back(i);
    }
    int ans=mod;

    for(int i=0;i+k-1<J.size();i++){
        int start=J[i];
        //deb(J[i]);
        int end=lower_bound(O.begin(),O.end(),J[i+k-1]+1)-O.begin();
        end=end+k-1;
        //deb(end);
        if(end>=O.size()) continue;
        end=O[end];
        end=lower_bound(I.begin(),I.end(),end)-I.begin();
        end=end+k-1;
        if(end>=I.size()) continue;
        end=I[end];
        ans=min(ans,end-start+1);
    }   
    if(ans==mod) cout<<"-1\n";
    else cout<<ans-3*k<<endl;



    return(0);
    
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:34:22: 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]
   34 |     for(int i=0;i+k-1<J.size();i++){
      |                 ~~~~~^~~~~~~~~
ho_t2.cpp:40:15: 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]
   40 |         if(end>=O.size()) continue;
      |            ~~~^~~~~~~~~~
ho_t2.cpp:44:15: 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]
   44 |         if(end>=I.size()) continue;
      |            ~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 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 1 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 2 ms 392 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 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 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 1 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 2 ms 392 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 364 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 2 ms 492 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 384 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 492 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 2 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 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 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 1 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 2 ms 392 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 364 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 2 ms 492 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 384 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 492 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 2 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 12 ms 2396 KB Output is correct
37 Correct 14 ms 2912 KB Output is correct
38 Correct 16 ms 2912 KB Output is correct
39 Correct 13 ms 3000 KB Output is correct
40 Correct 11 ms 3044 KB Output is correct
41 Correct 12 ms 3044 KB Output is correct
42 Correct 13 ms 2916 KB Output is correct
43 Correct 6 ms 1856 KB Output is correct
44 Correct 9 ms 2168 KB Output is correct
45 Correct 10 ms 2984 KB Output is correct
46 Correct 10 ms 2984 KB Output is correct
47 Correct 10 ms 3044 KB Output is correct
48 Correct 11 ms 3016 KB Output is correct
49 Correct 7 ms 1892 KB Output is correct
50 Correct 10 ms 3012 KB Output is correct
51 Correct 10 ms 3044 KB Output is correct
52 Correct 6 ms 2520 KB Output is correct
53 Correct 7 ms 2912 KB Output is correct
54 Correct 9 ms 3312 KB Output is correct
55 Correct 8 ms 3312 KB Output is correct
56 Correct 6 ms 3312 KB Output is correct