| Task: | HIIT Generation |
| Sender: | Oispa nutellaa |
| Submission time: | 2018-05-26 13:36:20 +0300 |
| Language: | C++ |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.10 s | details |
| #2 | ACCEPTED | 0.32 s | details |
| #3 | ACCEPTED | 0.10 s | details |
| #4 | ACCEPTED | 0.01 s | details |
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));
}
}
}
}
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 |
