Submission #1110012

#TimeUsernameProblemLanguageResultExecution timeMemory
1110012quannnguyen2009JJOOII 2 (JOI20_ho_t2)C++17
0 / 100
1 ms336 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...