Submission #1200906

#TimeUsernameProblemLanguageResultExecution timeMemory
1200906PlayVoltzJJOOII 2 (JOI20_ho_t2)C++20
100 / 100
30 ms6872 KiB
#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

int n, k, ans=LLONG_MAX/2;
vector<vector<int> > psum;

int bs(int a, int i){
	int low=a-1, high=n+1;
	while (low+1<high){
		int mid=(low+high)/2;
		if (psum[i][mid]-psum[i][a-1]>=k)high=mid;
		else low=mid;
	}
	return high;
}

int32_t main(){
	string s;
	cin>>n>>k>>s;
	psum.resize(3, vector<int>(n+1, 0));
	for (int i=0; i<n; ++i){
		for (int j=0; j<3; ++j)psum[j][i+1]+=psum[j][i];
		++psum[(s[i]=='J'?0:(s[i]=='O'?1:2))][i+1];
	}
	for (int i=1; i<=n; ++i){
		int id=bs(i, 0);
		id=bs(id+1, 1), id=bs(id+1, 2);
		if (id<=n)ans=min(ans, id-i+1-3*k);
	}
	cout<<(ans==LLONG_MAX/2?-1:ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...