CSES - HIIT Open 2018 - Results
Submission details
Task:HIIT Generation
Sender:Tefyn virallinen maajoukkue
Submission time:2018-05-26 13:44:36 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.06 sdetails
#2ACCEPTED0.18 sdetails
#3ACCEPTED0.06 sdetails
#4ACCEPTED0.01 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:34:16: warning: array subscript has type 'char' [-Wchar-subscripts]
         cc[m[i]]++;
                ^

Code

#include <bits/stdc++.h>

using namespace std;

int n; 
char m[10000000];

string expand(string c, int i, int hc, int ic, int tc){
    if(i == n)
        return c;
    if(c[0] == 'H' && hc == 0)
        return c;
    if(c[0] == 'I' && ic == 0)
        return c;
    if(c[0] == 'T' && tc == 0)
        return c;
    if(c[0] == m[i]){
        if(c[0] == 'H')
            hc--;
        if(c[0] == 'I')
            ic--;
        if(c[0] == 'T')
            tc--;
        return expand("H", i+1, hc, ic, tc)+expand("I", i+1, hc, ic, tc)+expand("I", i+1, hc, ic, tc)+expand("T", i+1, hc, ic, tc);
    }
    else
        return expand(c, i+1, hc, ic, tc);
}
int cc[256];
int main(){
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> m[i];
        cc[m[i]]++;
    }
    cout << expand("H", 0, cc['H'], cc['I'], cc['T'])+expand("I", 0, cc['H'], cc['I'], cc['T'])+expand("I", 0, cc['H'], cc['I'], cc['T'])+expand("T", 0, cc['H'], cc['I'], cc['T']) << endl;
    return 0;
}

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