CSES - HIIT Open 2018 - Results
Submission details
Task:HIIT Generation
Sender:Oispa nutellaa
Submission time:2018-05-26 13:36:20 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.10 sdetails
#2ACCEPTED0.32 sdetails
#3ACCEPTED0.10 sdetails
#4ACCEPTED0.01 sdetails

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