Submission #486189

# Submission time Handle Problem Language Result Execution time Memory
486189 2021-11-10T18:15:58 Z Sho10 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
9 ms 5476 KB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define aint(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 998244353
#define PI 3.14159265359
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,k,pref[4][200005];
string s;
int32_t main(){
CODE_START;
cin>>n>>k;
cin>>s;
for(ll i=0;i<s.size();i++)
{
    pref[0][i+1]=pref[0][i];
    pref[1][i+1]=pref[1][i];
    pref[2][i+1]=pref[2][i];
    if(s[i]=='J'){
        pref[0][i+1]++;
    }else if(s[i]=='O'){
    pref[1][i+1]++;
    }else {
    pref[2][i+1]++;
    }
}
ll ans=LINF,i=1,j=1,pos=1;
for(ll l=1;l<=n;l++)
{
    while(i<=n&&pref[0][i]-pref[0][l-1]<k){
        i++;
    }
    while(j<=n&&pref[1][j]-pref[1][i-1]<k){
        j++;
    }
    while(pos<=n&&pref[2][pos]-pref[2][j-1]<k){
pos++;
    }
    if(i<=n&&j<=n&&pos<=n){
        ans=min(ans,pos-l+1);
    }
}
if(ans==LINF){
    ans=3*k-1;
}
ans-=3*k;
cout<<ans<<endl;
}

Compilation message

ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:26:13: 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]
   26 | for(ll i=0;i<s.size();i++)
      |            ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 404 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 404 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 6 ms 5092 KB Output is correct
37 Correct 7 ms 5464 KB Output is correct
38 Correct 7 ms 5448 KB Output is correct
39 Correct 7 ms 5464 KB Output is correct
40 Correct 6 ms 5464 KB Output is correct
41 Correct 9 ms 5464 KB Output is correct
42 Correct 7 ms 5464 KB Output is correct
43 Correct 4 ms 3532 KB Output is correct
44 Correct 5 ms 4312 KB Output is correct
45 Correct 6 ms 5464 KB Output is correct
46 Correct 6 ms 5464 KB Output is correct
47 Correct 6 ms 5472 KB Output is correct
48 Correct 6 ms 5464 KB Output is correct
49 Correct 4 ms 3804 KB Output is correct
50 Correct 6 ms 5464 KB Output is correct
51 Correct 6 ms 5464 KB Output is correct
52 Correct 5 ms 5336 KB Output is correct
53 Correct 5 ms 5464 KB Output is correct
54 Correct 4 ms 5476 KB Output is correct
55 Correct 4 ms 5464 KB Output is correct
56 Correct 4 ms 5472 KB Output is correct