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

Code

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

using namespace std;


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

    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;

    char *c = new char[n];
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    while (transf_p >= 0) {
        int t_id = transf[transf_p];
        int letter_id = letter[letter_p];
        char c_to_be_printed;

        if (letter_id == 0) c_to_be_printed = 'H';
        else if (letter_id == 1 || letter_id == 2) c_to_be_printed = 'I';
        else c_to_be_printed = 'T';
        // cout << "t_id " << t_id << " letter " << c_to_be_printed << endl;

        bool addTransf = false;
        for (int next_t_id = t_id + 1; next_t_id < n; next_t_id++) {
            // cout << " trying to apply transform " << next_t_id << endl;
            if (c[next_t_id] == c_to_be_printed) { // if this transformation will apply to the letter
                // 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;
                addTransf = true;
                break;
            }
        }
        if (!addTransf) {
            // 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[] c;
    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:

input
333332
H
H
H
H
...

correct output
HIITIITIITIITIITIITIITIITIITII...

user output
(empty)

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