Code Submission Evaluation System Login

CSES - HIIT Open 2018

HIIT Open 2018

Contest start:2018-05-26 11:00:00
Contest end:2018-05-26 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2018-05-26 11:23:27
2018-05-26 11:22:47
Task:HIIT Generation
Sender:Ukkonen Fan Club
Submission time:2018-05-26 11:23:27
Status:READY
Result:ACCEPTED

Show test data

Code

#include<bits/stdc++.h>
using namespace std;
int n;

int H[1222333];
int I[1222333];
int T[1222333];
char t[1222333];


void r(int p){
    if (H[p]==n+1) cout << "H";
    else r(H[p]);
    if (I[p]==n+1) cout << "II";
    else r(I[p]), r(I[p]);
    if (T[p]==n+1) cout << "T";
    else r(T[p]);
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
    for (int i=0;i<n;++i) cin >> t[i];
    H[n]=n+1;
    I[n]=n+1;
    T[n]=n+1;
    for (int i=n-1;i>=0;--i){
        H[i]=H[i+1];
        I[i]=I[i+1];
        T[i]=T[i+1];
        if (t[i]=='H') H[i]=i+1;
        if (t[i]=='I') I[i]=i+1;
        if (t[i]=='T') T[i]=i+1;
    }
    r(0);
    cout << "\n";
}