Submission #507533

# Submission time Handle Problem Language Result Execution time Memory
507533 2022-01-12T16:54:38 Z maco1503 JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
7 ms 5488 KB
#include <bits/stdc++.h>
#define rpd ios_base :: sync_with_stdio(0); cin.tie(0);
#define ll long long
#define fs first
#define sc second
#define pb push_back
#define mod 666013
#define NMAX 100000 + 5
#define inf LLONG_MAX
using namespace std;
ll n,k,mat[4][200005];
int main()
{
    rpd;
    cin>>n>>k;
    string s;
    cin>>s;
    for(ll i=0;i<s.size();i++)
    {
    mat[0][i+1]=mat[0][i];
    mat[1][i+1]=mat[1][i];
    mat[2][i+1]=mat[2][i];
    if(s[i]=='J'){
        mat[0][i+1]++;
    }else if(s[i]=='O'){
    mat[1][i+1]++;
    }else {
    mat[2][i+1]++;
    }
    }
//    for(int i=0;i<=2;i++,cout<<'\n')
//        for(int j=1;j<=n;j++)cout<<mat[i][j]<<' ';
    ll i=1,j=1,ans=inf,pos=1;
    for(ll l=1;l<=n;l++)
    {
        while(i<=n&&mat[0][i]-mat[0][l-1]<k){
        i++;
        }
        while(j<=n&&mat[1][j]-mat[1][i-1]<k){
        j++;
        }

        while(pos<=n&&mat[2][pos]-mat[2][j-1]<k){
        pos++;
        }
        if(i<=n&&j<=n&&pos<=n){
        ans=min(ans,pos-l+1);
        }

    }
    if(ans==inf){
    ans=3*k-1;
    }
    ans-=3*k;
    cout<<ans<<'\n';

    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:18:17: 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]
   18 |     for(ll i=0;i<s.size();i++)
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 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 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 376 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 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 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 376 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 6 ms 5064 KB Output is correct
37 Correct 7 ms 5464 KB Output is correct
38 Correct 7 ms 5464 KB Output is correct
39 Correct 7 ms 5400 KB Output is correct
40 Correct 7 ms 5464 KB Output is correct
41 Correct 7 ms 5468 KB Output is correct
42 Correct 7 ms 5488 KB Output is correct
43 Correct 4 ms 3516 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 5464 KB Output is correct
48 Correct 6 ms 5452 KB Output is correct
49 Correct 4 ms 3808 KB Output is correct
50 Correct 6 ms 5484 KB Output is correct
51 Correct 6 ms 5456 KB Output is correct
52 Correct 5 ms 5336 KB Output is correct
53 Correct 5 ms 5480 KB Output is correct
54 Correct 4 ms 5464 KB Output is correct
55 Correct 4 ms 5456 KB Output is correct
56 Correct 4 ms 5452 KB Output is correct