CSES - HIIT Open 2018 - Results
Submission details
Task:HIIT Generation
Sender:Lucinda
Submission time:2018-05-26 14:53:35
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.28 sdetails
#3ACCEPTED0.05 sdetails
#4ACCEPTED0.01 sdetails

Code

#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>

using namespace std;


int main() {
    int n;
    cin >> n;

    char l[4] = {'H', 'I', 'I', 'T'};

    int *transf = new int[n + 1];
    int *letter = new int[n + 1];
    int transf_p = 0;
    int letter_p = 0;
    transf[0] = -1;
    letter[0] = 0;

    set<int> h_set;
    set<int> i_set;
    set<int> t_set;

    for (int j = 0; j < n; j++) {
        char ch;
        cin >> ch;
        if (ch == 'H') h_set.insert(j);
        else if (ch == 'I') i_set.insert(j);
        else t_set.insert(j);
    }

    set<int> t[4] = {h_set, i_set, i_set, t_set};

    while (transf_p >= 0) {
        int t_id = transf[transf_p];
        int letter_id = letter[letter_p];
        char c_to_be_printed = l[letter_id];

        // cout << "t_id " << t_id << " letter " << c_to_be_printed << endl;
        
        auto next_t_id_i = t[letter_id].upper_bound(t_id);
        if (next_t_id_i != t[letter_id].end()) {
            int next_t_id = *next_t_id_i;
            // cout << "add transformation " << next_t_id << endl;
            if (letter_id == 3) {letter_p--; transf_p--;}
            else letter[letter_p] = letter_id + 1;

            transf[++transf_p] = next_t_id;
            letter[++letter_p] = 0;
        } else {
            // cout << "print ";
            cout << c_to_be_printed;
            if (letter_id == 3) {letter_p--; transf_p--;}
            else letter[letter_p] = letter_id + 1;
        }
    }
    cout << endl;

    delete[] transf;
    delete[] letter;
}

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