CSES - HIIT Open 2018 - Results
Submission details
Task:HIIT Generation
Sender:Ukkonen Fan Club
Submission time:2018-05-26 11:23:27 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.03 sdetails
#2ACCEPTED0.07 sdetails
#3ACCEPTED0.03 sdetails
#4ACCEPTED0.01 sdetails

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";
}

Test details

Test 1

Verdict: ACCEPTED

input
17
I
I
I
I
...

correct output
HHHHHHHHHHHHHHHHHHIITHIITTHHII...

user output
HHHHHHHHHHHHHHHHHHIITHIITTHHII...

Test 2

Verdict: ACCEPTED

input
333332
H
H
H
H
...

correct output
HIITIITIITIITIITIITIITIITIITII...

user output
HIITIITIITIITIITIITIITIITIITII...

Test 3

Verdict: ACCEPTED

input
24
H
T
H
T
...

correct output
HIIHIITIIHIIHIITIIHIITIIHIIHII...

user output
HIIHIITIIHIIHIITIIHIITIIHIIHII...

Test 4

Verdict: ACCEPTED

input
0

correct output
HIIT

user output
HIIT