10049 | 2024-03-25 20:09:59 | 111 | Nemzetközi Rántott Hús Fesztivál | cpp17 | Runtime error 0/100 | 592ms | 359464 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Runtime error | 3ms | 2104 KiB | ||||
2 | Runtime error | 4ms | 4064 KiB | ||||
subtask2 | 0/7 | ||||||
3 | Runtime error | 3ms | 2380 KiB | ||||
4 | Runtime error | 3ms | 2524 KiB | ||||
subtask3 | 0/9 | ||||||
5 | Runtime error | 4ms | 4472 KiB | ||||
6 | Runtime error | 3ms | 4712 KiB | ||||
7 | Runtime error | 4ms | 4928 KiB | ||||
subtask4 | 0/14 | ||||||
8 | Runtime error | 462ms | 349424 KiB | ||||
9 | Time limit exceeded | 592ms | 175880 KiB | ||||
10 | Time limit exceeded | 578ms | 176016 KiB | ||||
11 | Runtime error | 460ms | 349748 KiB | ||||
12 | Time limit exceeded | 549ms | 176252 KiB | ||||
13 | Runtime error | 453ms | 349836 KiB | ||||
14 | Time limit exceeded | 578ms | 176432 KiB | ||||
15 | Runtime error | 455ms | 349900 KiB | ||||
subtask5 | 0/11 | ||||||
16 | Runtime error | 3ms | 4004 KiB | ||||
17 | Runtime error | 3ms | 3808 KiB | ||||
18 | Runtime error | 3ms | 3832 KiB | ||||
subtask6 | 0/29 | ||||||
19 | Runtime error | 4ms | 5576 KiB | ||||
20 | Runtime error | 3ms | 5936 KiB | ||||
21 | Runtime error | 3ms | 5884 KiB | ||||
22 | Runtime error | 4ms | 6208 KiB | ||||
subtask7 | 0/30 | ||||||
23 | Time limit exceeded | 586ms | 178696 KiB | ||||
24 | Time limit exceeded | 583ms | 178808 KiB | ||||
25 | Time limit exceeded | 574ms | 178992 KiB | ||||
26 | Runtime error | 469ms | 355696 KiB | ||||
27 | Runtime error | 460ms | 356080 KiB | ||||
28 | Time limit exceeded | 550ms | 180072 KiB | ||||
29 | Runtime error | 465ms | 357204 KiB | ||||
30 | Time limit exceeded | 582ms | 179324 KiB | ||||
31 | Time limit exceeded | 579ms | 179708 KiB | ||||
32 | Runtime error | 460ms | 358172 KiB | ||||
33 | Time limit exceeded | 578ms | 181332 KiB | ||||
34 | Runtime error | 458ms | 359432 KiB | ||||
35 | Runtime error | 469ms | 359464 KiB | ||||
36 | Runtime error | 449ms | 350984 KiB | ||||
37 | Runtime error | 453ms | 351136 KiB | ||||
38 | Runtime error | 449ms | 351100 KiB | ||||
39 | Runtime error | 449ms | 350980 KiB | ||||
40 | Time limit exceeded | 574ms | 181804 KiB |