Code Submission Evaluation System Login

CSES - HIIT Open 2018

HIIT Open 2018

Contest start:2018-05-26 11:00:00
Contest end:2018-05-26 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2018-05-26 14:21:13
2018-05-26 11:54:16
2018-05-26 11:32:54
2018-05-26 11:26:35
2018-05-26 11:16:28
Task:HIIT Generation
Sender:Puhi~
Submission time:2018-05-26 14:21:13
Status:READY
Result:ACCEPTED

Show test data

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');
}