CSES - HIIT Open 2018 - Results
Submission details
Task:HIIT Generation
Sender:KnowYourArchitecture
Submission time:2018-05-26 12:49:51 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#10.07 sdetails
#20.15 sdetails
#30.05 sdetails
#4ACCEPTED0.02 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 : "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:

input
17
I
I
I
I
...

correct output
HHHHHHHHHHHHHHHHHHIITHIITTHHII...

user output
HHHHHHHHHHHHHHHHHHIITHIITTH...

Test 2

Verdict:

input
333332
H
H
H
H
...

correct output
HIITIITIITIITIITIITIITIITIITII...

user output
HIITIITIITIITIITIITIITI...

Test 3

Verdict:

input
24
H
T
H
T
...

correct output
HIIHIITIIHIIHIITIIHIITIIHIIHII...

user output
HIIHIITIIHIIHIITIIHIITI...

Test 4

Verdict: ACCEPTED

input
0

correct output
HIIT

user output
HIIT