Submission #1023719

#TimeUsernameProblemLanguageResultExecution timeMemory
1023719vjudge1JJOOII 2 (JOI20_ho_t2)C++17
13 / 100
2032 ms860 KiB
#include "bits/stdc++.h"
#define int long long
using namespace std;
const int mod = 1000000007;
signed main() {
  	ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
   	int n,k;
   	cin>>n>>k;
   	string s;
   	cin>>s;
   	int mn=1e18;
	for(int l=0;l<n;l++){
		map<char,int>mp;
		for(int r=l;r<n;r++){
			if(s[r]=='J'){
			mp[s[r]]++;
			}
			if(s[r]=='O' and mp['J']>=k){
				mp[s[r]]++;
			}
			if(s[r]=='I' and mp['O']>=k){
				mp[s[r]]++;
			}
			if(mp['J']>=k and mp['I']>=k and mp['O']>=k){
				mn=min(mn,((r+1)-(l+1)+1)-(3*k));
				break;
			}
//			cout<<l<<" "<<r<<endl;
//			cout<<s2<<endl<<endl;
		}
	}
	if(mn==1e18){
		cout<<-1;
	}else{
		cout<<mn;
	}
	//  int t;
//  cin>>t;
//  while(t--){
//  int n, m; cin >> n >> m;
////  f.resize(n + 1), inv.resize(n + 1);
////  
////  f[0] = inv[0] = 1;
////  for(int i=1;i<=n;i++){
////    f[i] = f[i - 1] * 1ll * i % mod;
////    
////    inv[i] = binary_power(f[i], mod - 2, mod);
////  }
//  
//  cout<<bin(n,m)<<"\n";
//}
return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...