12912022-03-30 14:08:19k_balintNemzetközi Rántott Hús Fesztiválcpp14Wrong answer 23/100120ms31180 KiB
#include <bits/stdc++.h>
using namespace std;

int n;
string s;
int suf[1000006];
int best[1000006];
stack<int> st;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin>>n>>s;

    for(int i=n-1;i>=0;i--){
        if(s[i]=='H'){
            best[i]=i;
            st.push(i);
        }
        else{
            if(!st.empty()) st.pop();
            best[i]=st.empty()?n:st.top();
        }
    }

    for(int i=n-1;i>=0;i--){
        suf[i]=suf[i+1]+(s[i]=='K');
    }

    for(int i=0;i<n;i++){
        if(best[i] != n){
            cout << (best[i]-i)/2 << ' ';
        }

        else{
            cout << min((n-i)/2,n-i-suf[i]) << ' ';
        }
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted2ms1820 KiB
2Wrong answer2ms1984 KiB
subtask20/7
3Wrong answer1ms1872 KiB
4Accepted1ms1876 KiB
subtask39/9
5Accepted2ms1936 KiB
6Accepted2ms1952 KiB
7Accepted2ms1956 KiB
subtask414/14
8Accepted101ms20660 KiB
9Accepted103ms21636 KiB
10Accepted105ms22636 KiB
11Accepted103ms23672 KiB
12Accepted100ms24644 KiB
13Accepted112ms25632 KiB
14Accepted100ms26612 KiB
15Accepted93ms27552 KiB
subtask50/11
16Wrong answer1ms8008 KiB
17Accepted1ms8020 KiB
18Accepted1ms8020 KiB
subtask60/29
19Wrong answer2ms8068 KiB
20Accepted2ms8080 KiB
21Accepted2ms8164 KiB
22Accepted2ms8092 KiB
subtask70/30
23Wrong answer104ms26788 KiB
24Accepted120ms27824 KiB
25Accepted108ms26768 KiB
26Wrong answer111ms27708 KiB
27Accepted104ms28704 KiB
28Accepted109ms27712 KiB
29Accepted104ms28648 KiB
30Wrong answer104ms29628 KiB
31Wrong answer104ms28392 KiB
32Accepted107ms27468 KiB
33Accepted109ms28444 KiB
34Accepted104ms28444 KiB
35Accepted109ms28408 KiB
36Accepted94ms29384 KiB
37Accepted96ms28196 KiB
38Accepted98ms29176 KiB
39Accepted96ms30164 KiB
40Accepted97ms31180 KiB