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:36:20
Task:HIIT Generation
Sender:Oispa nutellaa
Submission time:2018-05-26 13:36:20
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
#define ull unsigned long long

using namespace std;

int n;
vector<char> movet;
set<int> H, I, T; // Move indeksit
char cha;
stack<pair<string, int>> stk;

int main() {
	cin >> n;
	for(int i=0; i<n; i++) {
		cin >> cha;
		movet.push_back(cha);
		if(cha=='H')
			H.insert(i);
		else if(cha=='I')
			I.insert(i);
		else
			T.insert(i);
	}
	stk.push(make_pair("T", -1));
	stk.push(make_pair("I", -1));
	stk.push(make_pair("I", -1));
	stk.push(make_pair("H", -1));
	while(!stk.empty()) {
		auto p = stk.top();
		stk.pop();
		if(p.first=="H") {
			auto it = H.upper_bound(p.second);
			if(it==H.end()) {
				cout << p.first;
			} else {
					stk.push(make_pair("T", *it));
					stk.push(make_pair("I", *it));
					stk.push(make_pair("I", *it));
					stk.push(make_pair("H", *it));
			}
		} else if(p.first=="I") {
			auto it = I.upper_bound(p.second);
			if(it==I.end()) {
				cout << p.first;
			} else {
					stk.push(make_pair("T", *it));
					stk.push(make_pair("I", *it));
					stk.push(make_pair("I", *it));
					stk.push(make_pair("H", *it));
			}
		} else {
			auto it = T.upper_bound(p.second);
			if(it==T.end()) {
				cout << p.first;
			} else {
					stk.push(make_pair("T", *it));
					stk.push(make_pair("I", *it));
					stk.push(make_pair("I", *it));
					stk.push(make_pair("H", *it));
			}
		}
	}



}