Submission #361352

# Submission time Handle Problem Language Result Execution time Memory
361352 2021-01-29T11:59:47 Z shahriarkhan JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
339 ms 1692 KB
#include<bits/stdc++.h>
using namespace std ;

const int mx = 2e5 + 5 ;

int n , k , ind[3][mx] , pos[mx] , siz[3] ;

string s ;

int bs(int low , int high , int val , int a[])
{
    while(low<high)
    {
        int mid = (low+high)>>1 ;
        if(a[mid]<val) low = mid + 1 ;
        else high = mid ;
    }
    return low ;
}

int check(int x)
{
    for(int i = 0 ; i <= x ; ++i)
    {
        int l = i + 1 , r = n - x + i , cnt = 0 ;
        for(int j = 0 ; j < 3 ; ++j)
        {
            if(l>ind[j][siz[j]]) break ;
            int pos = bs(1,siz[j],l,ind[j]) ;
            if(((pos+k-1)<=siz[j]) && (ind[j][pos+k-1]<=r))
            {
                ++cnt , l = ind[j][pos+k-1] + 1 ;
            }
        }
        if(cnt==3) return 1 ;
    }
    return 0 ;
}

int main()
{
    scanf("%d%d",&n,&k) ;
    cin>>s ;
    for(int i = 0 ; i < n ; ++i)
    {
        if(s[i]=='J')
        {
            ++siz[0] ;
            ind[0][siz[0]] = i + 1 ;
        }
        else if(s[i]=='O')
        {
            ++siz[1] ;
            ind[1][siz[1]] = i + 1 ;
        }
        else
        {
            ++siz[2] ;
            ind[2][siz[2]] = i + 1 ;
        }
    }
    int low = 0 , high = n ;

    if(!check(0))
    {
        puts("-1") ;
        return 0 ;
    }
    while(low<high)
    {
        int mid = (low+high+1)>>1 ;
        if(check(mid)) low = mid ;
        else high = mid - 1 ;
    }
    printf("%d\n",n-low-(3*k)) ;
    return 0 ;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |     scanf("%d%d",&n,&k) ;
      |     ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 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 0 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 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 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 0 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 1 ms 364 KB Output is correct
14 Correct 0 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 3 ms 364 KB Output is correct
20 Correct 3 ms 364 KB Output is correct
21 Correct 3 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 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 1 ms 364 KB Output is correct
27 Correct 1 ms 364 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 364 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
33 Correct 2 ms 364 KB Output is correct
34 Correct 2 ms 364 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 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 0 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 1 ms 364 KB Output is correct
14 Correct 0 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 3 ms 364 KB Output is correct
20 Correct 3 ms 364 KB Output is correct
21 Correct 3 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 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 1 ms 364 KB Output is correct
27 Correct 1 ms 364 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 364 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
33 Correct 2 ms 364 KB Output is correct
34 Correct 2 ms 364 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 44 ms 1404 KB Output is correct
37 Correct 92 ms 1660 KB Output is correct
38 Correct 90 ms 1404 KB Output is correct
39 Correct 339 ms 1404 KB Output is correct
40 Correct 106 ms 1648 KB Output is correct
41 Correct 258 ms 1692 KB Output is correct
42 Correct 301 ms 1532 KB Output is correct
43 Correct 25 ms 1148 KB Output is correct
44 Correct 31 ms 1276 KB Output is correct
45 Correct 52 ms 1412 KB Output is correct
46 Correct 40 ms 1532 KB Output is correct
47 Correct 43 ms 1404 KB Output is correct
48 Correct 40 ms 1472 KB Output is correct
49 Correct 5 ms 1148 KB Output is correct
50 Correct 7 ms 1404 KB Output is correct
51 Correct 7 ms 1680 KB Output is correct
52 Correct 8 ms 1552 KB Output is correct
53 Correct 8 ms 1404 KB Output is correct
54 Correct 146 ms 1660 KB Output is correct
55 Correct 74 ms 1660 KB Output is correct
56 Correct 25 ms 1660 KB Output is correct