Submission #1111345

# Submission time Handle Problem Language Result Execution time Memory
1111345 2024-11-12T07:04:48 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
14 ms 4604 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pll pair<ll, ll>
ll n, k, pO[200001], pJ[200001], pI[200001], ans=1e18;
string str;
vector<ll> J, I;


int main(){
    cin >> n >> k;
    cin >> str;
    for(int i=1; i<=n; i++){
        if(str[i-1]=='J')
            J.push_back(i);
        if(str[i-1]=='I')
            I.push_back(i);
        if(str[i-1]=='O')pO[i]=pO[i-1]+1;
        else pO[i]=pO[i-1];
    }
    if(J.size()<k || I.size()<k || pO[n]<k){
        cout << -1 << endl;
        return 0;
    }
    for(int i=J.size()-1; i>=k-1; i--){
        int l=0, r=I.size()-1, mid, back=-1;
        while(l<=r){
            mid=(l+r)/2;
            if(pO[I[mid]]-pO[J[i]]<k){
                l=mid+1;
            }else{
                back=mid;
                r=mid-1;
            }
        }
        if(back==-1 || I.size() - back < k)continue;
        ans=min(ans, I[back+k-1]-J[i-k+1]+1-3*k);
    }
    if(ans==1e18)ans=-1;
    cout << ans << endl;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:23:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   23 |     if(J.size()<k || I.size()<k || pO[n]<k){
      |        ~~~~~~~~^~
ho_t2.cpp:23:30: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   23 |     if(J.size()<k || I.size()<k || pO[n]<k){
      |                      ~~~~~~~~^~
ho_t2.cpp:38:40: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   38 |         if(back==-1 || I.size() - back < k)continue;
      |                        ~~~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 504 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 504 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 504 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 504 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 9 ms 3180 KB Output is correct
37 Correct 11 ms 4012 KB Output is correct
38 Correct 11 ms 3996 KB Output is correct
39 Correct 10 ms 4032 KB Output is correct
40 Correct 14 ms 3856 KB Output is correct
41 Correct 14 ms 3936 KB Output is correct
42 Correct 11 ms 4028 KB Output is correct
43 Correct 7 ms 2396 KB Output is correct
44 Correct 8 ms 2724 KB Output is correct
45 Correct 10 ms 4060 KB Output is correct
46 Correct 9 ms 4028 KB Output is correct
47 Correct 9 ms 3940 KB Output is correct
48 Correct 9 ms 3884 KB Output is correct
49 Correct 7 ms 2644 KB Output is correct
50 Correct 10 ms 3924 KB Output is correct
51 Correct 11 ms 4028 KB Output is correct
52 Correct 7 ms 3468 KB Output is correct
53 Correct 8 ms 3924 KB Output is correct
54 Correct 8 ms 4436 KB Output is correct
55 Correct 8 ms 4604 KB Output is correct
56 Correct 7 ms 4436 KB Output is correct