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:00:50
2018-05-26 12:49:51
Task:HIIT Generation
Sender:KnowYourArchitecture
Submission time:2018-05-26 13:00:50
Status:READY
Result:ACCEPTED

Show test data

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