CSES - HIIT Open 2018 - Results
Submission details
Task:HIIT Generation
Sender:HIIT AND RUN
Submission time:2018-05-26 13:06:13 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.07 sdetails
#2ACCEPTED0.30 sdetails
#3ACCEPTED0.05 sdetails
#4ACCEPTED0.01 sdetails

Compiler report

input/code.cpp:16:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^

Code

#include <bits/stdc++.h>

using namespace std;

set<int> H, I, T;

deque<pair<char,int>> pino;

void push_hiit(int seq) {
    pino.push_back({'T', seq});
    pino.push_back({'I', seq});
    pino.push_back({'I', seq});
    pino.push_back({'H', seq});
}

main () {
 
    int n;
    cin >> n;
    
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        
        if (s == "H")
            H.insert(i+1);
        
        if (s == "I")
            I.insert(i+1);
        
        if (s == "T")
            T.insert(i+1);
    }
    
    push_hiit(0);
    
    while (pino.size()) {
     
        auto pari = pino.back();
        pino.pop_back();
        
        int t = pari.second;
        char c = pari.first;
        
        int next = 0;
        
        if (c == 'H') {
            auto inext = H.upper_bound(t);
            if (inext != H.end())
                next = *inext;
        }
        
        if (c == 'I') {
            auto inext = I.upper_bound(t);
            if (inext != I.end())
                next = *inext;
        }
        
        if (c == 'T') {
            auto inext = T.upper_bound(t);
            if (inext != T.end())
                next = *inext;
        }
        
        if (next == 0) {
            cout << c;
        } else {
            push_hiit(next);
        }
        
    }
    
    cout << endl;
    
    
}

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