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 12:35:41
Task:HIIT Generation
Sender:barely div 2.8 burgeria
Submission time:2018-05-26 12:35:41
Status:READY
Result:ACCEPTED

Show test data

Compiler report

input/code.cpp: In function 'void update_list(std::vector<node*>&)':
input/code.cpp:38:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < cp.size(); i++) {
                  ~~^~~~~~~~~~~

Code

#include <iostream>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

typedef long long LL;


struct node {
	vector<node*> kids;
	char c;
};


vector<node*> hs;
vector<node*> is;
vector<node*> ts;

void expand(node * root) {
	node * h = new node(); h->c = 'H';
	node * i1 = new node(); i1->c = 'I';
	node * i2 = new node(); i2->c = 'I';
	node * t = new node(); t->c = 'T';
	root->kids.emplace_back(h);
	root->kids.emplace_back(i1);
	root->kids.emplace_back(i2);
	root->kids.emplace_back(t);
	hs.emplace_back(h);	
	is.emplace_back(i1);	
	is.emplace_back(i2);	
	ts.emplace_back(t);
}


void update_list(vector<node*> & cp) {
	for (int i = 0; i < cp.size(); i++) {
		node * n = cp[i];
		expand(n);
	}
}


void expand_char(char c) {
	if (c == 'H') {
		vector<node*> hcp = hs;
		hs.clear();
		update_list(hcp);
	}
	if (c == 'I') {
		vector<node*> icp = is;
		is.clear();
		update_list(icp);
	}
	if (c == 'T') {
		vector<node*> tcp = ts;
		ts.clear();
		update_list(tcp);
	}
}

void solve(vector<char> & c, node * n) {
	if (n->kids.size() == 0) {
		c.emplace_back(n->c);
		return;
	}
	for (auto kid : n->kids) {
		solve(c, kid);
	}
}


int main() {
	int n; cin >>n;
	node * root = new node();
	expand(root);
	for (int i = 0; i < n; i++) {
		char c; cin>>c;
		expand_char(c);
	}
	vector<char> c;
	solve(c, root);
	for (auto ch : c) cout << ch;
}



/*
int main() {
	int n; cin >>n;
	int hc = 0;
	int ic = 0;
	int tc = 0;
	vector<char> v;
	vector<int> hnext(n);
	vector<int> inext(n);
	vector<int> tnext(n);
	for (int i = 0; i < n; i++) {
		char c; cin >> c;
		v.emplace_back(c);
	}
	int hprev = n;
	int iprev = n;
	int tprev = n;
	for (int i = n-1; i >= 0; i--) {
		if (v[i] == 'H') hprev = i;
		if (v[i] == 'I') iprev = i;
		if (v[i] == 'T') tprev = i;
	}

}
*/