Submission #1110012

# Submission time Handle Problem Language Result Execution time Memory
1110012 2024-11-08T12:49:30 Z quannnguyen2009 JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 336 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
using namespace std;

const int N=2e5+5,mod=1e9+7,inf=1e18;

int n,k;
string s;
int co[N],cj[N],ci[N];

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>k>>s; s=" "+s;

    for(int i=1;i<=n;i++){
        co[i]=co[i-1];
        cj[i]=cj[i-1];
        ci[i]=ci[i-1];
        
        if(s[i]=='O') co[i]++;
        else if(s[i]=='J') cj[i]++;
        else ci[i]++;
    }

    int mn=inf;

    for(int i=1;i<=n;i++){
        int cnt=0;

        if(cj[i]<k) continue;

        int lo=1,hi=i;
        while(lo+1<hi){
            int mid=(lo+hi)>>1;
            if(cj[i]-cj[mid-1]>=k) lo=mid;
            else hi=mid;
        }
        cnt+=i-lo+1-k;

        lo=i;
        hi=n;
        while(lo+1<hi){
            int mid=(lo+hi)>>1;
            if(co[mid]-co[i]>=k) hi=mid;
            else lo=mid;
        }
        cnt+=hi-i-k;

        int nl=hi;
        if(ci[n]-ci[hi]<k) continue;

        lo=nl;
        hi=n;
        while(lo+1<hi){
            int mid=(lo+hi)>>1;
            if(ci[mid]-ci[nl]<k) lo=mid;
            else hi=mid;
        }
        cnt+=hi-nl-k;

        mn=min(mn,max(cnt,0LL));
    }

    if(mn==inf) cout<<-1;
    else cout<<mn;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -