100502024-03-25 20:11:28111Nemzetközi Rántott Hús Fesztiválcpp17Runtime error 0/100612ms358928 KiB
#include <bits/stdc++.h>
using namespace std;

// #define int long long

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin>>N;
	string S;
	cin>>S;
	vector<int>c(N+1),vk(N+1),vh(N+1),w(N+1),f(1);
	for(int i=0;i<N;i++){
		if(S[i]=='M'){
			f.push_back(i);
		}
		c[i+1]=c[i]+(S[i]!='K');
		vk[i+1]=(S[i]!='H'?vk[i]+1:vk[i]-1);
		vh[i+1]=(S[i]!='K'?vh[i]-1:vh[i]+1);
		w[i+1]=w[i]+(S[i]=='M');
	}
	f.push_back(N);
	vector<array<int,20>>tk(N+1),th(N+1);
	for(int i=0;i<N+1;i++){
		tk[i][0]=vk[i];
		th[i][0]=vh[i];
	}
	for(int j=1;j<20;j++){
		for(int l=0,r=1<<j-1;r<N+1;l++,r++){
			tk[l][j]=min({tk[l][j-1],tk[r][j-1]});
			th[l][j]=min({th[l][j-1],th[r][j-1]});
		}
	}
	auto qk=[&](int l,int r)->int{
		int i=__lg(r-l);
		return min({tk[l][i],tk[r-(1<<i)][i]});
	};
	auto qh=[&](int l,int r)->int{
		int i=__lg(r-l);
		return min({th[l][i],th[r-(1<<i)][i]});
	};
	return 1;
	for(int i=0;i<N;i++){
		int b=qk(i+1,N+1)-vk[i]>=0;
		if(b){
			int l=1,h=w[N]-w[i]+1;
			while(l<h){
				int m=(l+h)/2;
				int j=f[w[i]+m];
				int x=vk[j]-vk[i];
				if(qh(j,N+1)-vh[j]+x>=0){
					h=m;
				}
				else{
					l=m+1;
				}
			}
			cout<<c[N]-c[i]-(l-1)<<' ';
		}
		else{
			int l=i+1,h=N;
			while(l<h){
				int m=(l+h)/2;
				if(qk(i+1,m+1)-vk[i]>=0){
					l=m+1;
				}
				else{
					h=m;
				}
			}
			cout<<(l-1-i)/2<<' ';
		}
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error3ms1960 KiB
2Runtime error3ms3816 KiB
subtask20/7
3Runtime error3ms2304 KiB
4Runtime error3ms2508 KiB
subtask30/9
5Runtime error4ms4428 KiB
6Runtime error3ms4368 KiB
7Runtime error3ms4368 KiB
subtask40/14
8Runtime error465ms348828 KiB
9Time limit exceeded538ms348976 KiB
10Runtime error474ms349056 KiB
11Runtime error460ms349064 KiB
12Runtime error456ms349152 KiB
13Runtime error456ms349152 KiB
14Runtime error453ms349144 KiB
15Time limit exceeded578ms175900 KiB
subtask50/11
16Runtime error3ms3648 KiB
17Runtime error3ms3664 KiB
18Runtime error3ms3896 KiB
subtask60/29
19Runtime error4ms5492 KiB
20Runtime error4ms5572 KiB
21Runtime error3ms5572 KiB
22Runtime error3ms5828 KiB
subtask70/30
23Time limit exceeded612ms178288 KiB
24Runtime error472ms353428 KiB
25Time limit exceeded574ms178548 KiB
26Runtime error469ms355116 KiB
27Runtime error465ms355724 KiB
28Runtime error462ms356252 KiB
29Runtime error470ms356796 KiB
30Time limit exceeded587ms179148 KiB
31Runtime error467ms355432 KiB
32Time limit exceeded575ms181116 KiB
33Runtime error462ms358928 KiB
34Time limit exceeded564ms181520 KiB
35Time limit exceeded584ms181716 KiB
36Time limit exceeded588ms177460 KiB
37Time limit exceeded573ms177376 KiB
38Time limit exceeded572ms177548 KiB
39Time limit exceeded586ms177568 KiB
40Time limit exceeded586ms181812 KiB