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 13:44:36
2018-05-26 12:58:16
2018-05-26 12:56:45
Task:HIIT Generation
Sender:Tefyn virallinen maajoukkue
Submission time:2018-05-26 13:44:36
Status:READY
Result:ACCEPTED

Show test data

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