CSES - HIIT Open 2018 - Results
Submission details
Task:HIIT Generation
Sender:Ukkonen Fan Club
Submission time:2018-05-26 11:22:47
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.03 sdetails
#2ACCEPTED0.07 sdetails
#30.00 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]), 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:

input
24
H
T
H
T
...

correct output
HIIHIITIIHIIHIITIIHIITIIHIIHII...

user output
(empty)

Test 4

Verdict: ACCEPTED

input
0

correct output
HIIT

user output
HIIT