CSES - HIIT Open 2018 - Results
Submission details
Task:HIIT Generation
Sender:KnowYourArchitecture
Submission time:2018-05-26 13:00:50 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.07 sdetails
#2ACCEPTED0.14 sdetails
#3ACCEPTED0.05 sdetails
#4ACCEPTED0.01 sdetails

Code

#include <bits/stdc++.h>

using namespace std;

int n;
char chr[10000001];
int nexti[4][10000001];

void r(int i) {
	for(auto c : string("HIIT")) {
		int ni = -1;
		if(i < n) {
			if(c == 'H') ni = nexti[0][i];
			if(c == 'I') ni = nexti[1][i];
			if(c == 'T') ni = nexti[2][i];
		}

		if(ni == -1) {
			cout << c;
		} else {
			r(ni+1);
		}
	}
}

int main() {
	cin >> n;
	for(int j=0;j<n;j++) {
		cin >> chr[j];
	}
	int ph=-1,pi=-1,pt=-1;
	for(int j=n-1;j>=0;j--) {
		if(chr[j] == 'H') ph=j;
		if(chr[j] == 'I') pi=j;
		if(chr[j] == 'T') pt=j;
		nexti[0][j] = ph;
		nexti[1][j] = pi;
		nexti[2][j] = pt;
	}
	r(0);
	cout << 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