Submission #423369

# Submission time Handle Problem Language Result Execution time Memory
423369 2021-06-11T03:31:06 Z juggernaut JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
34 ms 3104 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
typedef long long ll;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef IOI2021SG
    #define printl(args...)printf(args)
#else
    #define printl(args...)((void)0)
#endif
int n,k;
string s;
int pref[200005][3];
int main(){
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    cin>>n>>k>>s;
    s=" "+s;
    for(int i=1;i<=n;i++){
        pref[i][0]=pref[i-1][0]+(s[i]=='J');
        pref[i][1]=pref[i-1][1]+(s[i]=='O');
        pref[i][2]=pref[i-1][2]+(s[i]=='I');
    }
    int mn=1e9;
    for(int i=1;i<=n;i++){
        int pivot=i-1;
        int l=i;
        int r=n;
        while(l<r){
            int mid=(l+r)>>1;
            if(pref[mid][0]-pref[pivot][0]>=k)r=mid;
            else l=mid+1;
        }
        if(pref[l][0]-pref[pivot][0]<k)continue;
        r=n;
        pivot=l-1;
        while(l<r){
            int mid=(l+r)>>1;
            if(pref[mid][1]-pref[pivot][1]>=k)r=mid;
            else l=mid+1;
        }
        if(pref[l][1]-pref[pivot][1]<k)continue;
        r=n;
        pivot=l-1;
        while(l<r){
            int mid=(l+r)>>1;
            if(pref[mid][2]-pref[pivot][2]>=k)r=mid;
            else l=mid+1;
        }
        if(pref[l][2]-pref[pivot][2]<k)continue;
        umin(mn,l-i+1);
    }
    if(mn==int(1e9))puts("-1");
    else printf("%d",mn-3*k);
}

Compilation message

ho_t2.cpp: In function 'void usaco(std::string)':
ho_t2.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 300 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 204 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 296 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 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 300 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 204 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 296 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 24 ms 2888 KB Output is correct
37 Correct 28 ms 3076 KB Output is correct
38 Correct 26 ms 3096 KB Output is correct
39 Correct 33 ms 3096 KB Output is correct
40 Correct 28 ms 3096 KB Output is correct
41 Correct 32 ms 3096 KB Output is correct
42 Correct 34 ms 3096 KB Output is correct
43 Correct 21 ms 1932 KB Output is correct
44 Correct 19 ms 2500 KB Output is correct
45 Correct 25 ms 3096 KB Output is correct
46 Correct 25 ms 3052 KB Output is correct
47 Correct 25 ms 3096 KB Output is correct
48 Correct 26 ms 3096 KB Output is correct
49 Correct 17 ms 2136 KB Output is correct
50 Correct 25 ms 3096 KB Output is correct
51 Correct 29 ms 3104 KB Output is correct
52 Correct 16 ms 2956 KB Output is correct
53 Correct 19 ms 3096 KB Output is correct
54 Correct 20 ms 3096 KB Output is correct
55 Correct 18 ms 3096 KB Output is correct
56 Correct 16 ms 3104 KB Output is correct