CSES - HIIT Open 2018 - Results
Submission details
Task:HIIT Generation
Sender:Puhi~
Submission time:2018-05-26 14:21:13
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.06 sdetails
#2ACCEPTED0.11 sdetails
#3ACCEPTED0.05 sdetails
#4ACCEPTED0.01 sdetails

Compiler report

input/code.cpp: In function 'void r(char, int)':
input/code.cpp:21:37: warning: 'tablesize' may be used uninitialized in this function [-Wmaybe-uninitialized]
         while (i + step < tablesize && table[i + step] <= y)  {
                ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~

Code

#include <iostream>
#include <stdio.h>

using namespace std;

int h[1000000];
int ii[1000000];
int t[1000000];
int hs, is, ts;

void r(char a, int y) {

    int *table;
    int tablesize;
    if (a == 'H') {table = h; tablesize = hs;}
    if (a == 'I') {table = ii; tablesize = is;}
    if (a == 'T') {table = t; tablesize = ts;}
    
    int i = -1;
    for (int step = 100000; step > 0; step /= 2) {
        while (i + step < tablesize && table[i + step] <= y)  {
            i += step;
        }
    }

    if (i + 1 != tablesize) {
        r('H', table[i+1]);
        r('I', table[i+1]);
        r('I', table[i+1]);
        r('T', table[i+1]);
        return;
    }

    putchar_unlocked(a);
}

int main() {
    int n;
    cin >> n;
    
    hs = is = ts = 0;
    for (int i = 0; i < n; i++) {
        char tmp;
        cin >> tmp;
        if (tmp == 'H') { h[hs++] = i;}
        if (tmp == 'I') { ii[is++] = i;}
        if (tmp == 'T') { t[ts++] = i;}
    }
    
    r('H', -1);
    r('I', -1);
    r('I', -1);
    r('T', -1);
    putchar_unlocked('\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: 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