10050 | 2024-03-25 20:11:28 | 111 | Nemzetközi Rántott Hús Fesztivál | cpp17 | Runtime error 0/100 | 612ms | 358928 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 | 1960 KiB | ||||
2 | Runtime error | 3ms | 3816 KiB | ||||
subtask2 | 0/7 | ||||||
3 | Runtime error | 3ms | 2304 KiB | ||||
4 | Runtime error | 3ms | 2508 KiB | ||||
subtask3 | 0/9 | ||||||
5 | Runtime error | 4ms | 4428 KiB | ||||
6 | Runtime error | 3ms | 4368 KiB | ||||
7 | Runtime error | 3ms | 4368 KiB | ||||
subtask4 | 0/14 | ||||||
8 | Runtime error | 465ms | 348828 KiB | ||||
9 | Time limit exceeded | 538ms | 348976 KiB | ||||
10 | Runtime error | 474ms | 349056 KiB | ||||
11 | Runtime error | 460ms | 349064 KiB | ||||
12 | Runtime error | 456ms | 349152 KiB | ||||
13 | Runtime error | 456ms | 349152 KiB | ||||
14 | Runtime error | 453ms | 349144 KiB | ||||
15 | Time limit exceeded | 578ms | 175900 KiB | ||||
subtask5 | 0/11 | ||||||
16 | Runtime error | 3ms | 3648 KiB | ||||
17 | Runtime error | 3ms | 3664 KiB | ||||
18 | Runtime error | 3ms | 3896 KiB | ||||
subtask6 | 0/29 | ||||||
19 | Runtime error | 4ms | 5492 KiB | ||||
20 | Runtime error | 4ms | 5572 KiB | ||||
21 | Runtime error | 3ms | 5572 KiB | ||||
22 | Runtime error | 3ms | 5828 KiB | ||||
subtask7 | 0/30 | ||||||
23 | Time limit exceeded | 612ms | 178288 KiB | ||||
24 | Runtime error | 472ms | 353428 KiB | ||||
25 | Time limit exceeded | 574ms | 178548 KiB | ||||
26 | Runtime error | 469ms | 355116 KiB | ||||
27 | Runtime error | 465ms | 355724 KiB | ||||
28 | Runtime error | 462ms | 356252 KiB | ||||
29 | Runtime error | 470ms | 356796 KiB | ||||
30 | Time limit exceeded | 587ms | 179148 KiB | ||||
31 | Runtime error | 467ms | 355432 KiB | ||||
32 | Time limit exceeded | 575ms | 181116 KiB | ||||
33 | Runtime error | 462ms | 358928 KiB | ||||
34 | Time limit exceeded | 564ms | 181520 KiB | ||||
35 | Time limit exceeded | 584ms | 181716 KiB | ||||
36 | Time limit exceeded | 588ms | 177460 KiB | ||||
37 | Time limit exceeded | 573ms | 177376 KiB | ||||
38 | Time limit exceeded | 572ms | 177548 KiB | ||||
39 | Time limit exceeded | 586ms | 177568 KiB | ||||
40 | Time limit exceeded | 586ms | 181812 KiB |