Code Submission Evaluation System Login

HIIT Open 2018

Start:2018-05-26 11:00:00
End:2018-05-26 16:00:00
 

Tasks | Messages | Scoreboard | Statistics


CSES - HIIT Open 2018 - Results
History
2018-05-26 14:53:35
2018-05-26 14:26:26
2018-05-26 14:10:44
2018-05-26 14:03:19
2018-05-26 13:08:32
Task:HIIT Generation
Sender:Lucinda
Submission time:2018-05-26 14:53:35
Language:C++
Status:READY
Result:ACCEPTED

Test results

testverdicttime (s)
#1ACCEPTED0.05 / 1.00details
#2ACCEPTED0.28 / 1.00details
#3ACCEPTED0.05 / 1.00details
#4ACCEPTED0.01 / 1.00details

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
I
I
I
I
I
I
I
I
I
I
I
I
I
view   save

correct output
HHHHHHHHHHHHHHHHHHIITHIITTHHII...
view   save

user output
HHHHHHHHHHHHHHHHHHIITHIITTHHII...
view   save

Test 2

Verdict: ACCEPTED

input
333332
H
H
H
H
H
H
H
H
H
H
H
H
H
H
H
H
H
H
H
...
view   save

correct output
HIITIITIITIITIITIITIITIITIITII...
view   save

user output
HIITIITIITIITIITIITIITIITIITII...
view   save

Test 3

Verdict: ACCEPTED

input
24
H
T
H
T
H
T
H
T
H
T
H
T
H
T
H
T
H
T
H
...
view   save

correct output
HIIHIITIIHIIHIITIIHIITIIHIIHII...
view   save

user output
HIIHIITIIHIIHIITIIHIITIIHIIHII...
view   save

Test 4

Verdict: ACCEPTED

input
0
view   save

correct output
HIIT
view   save

user output
HIIT
view   save