CSES - HIIT Open 2016 - Results
Submission details
Task:HIIT remains
Sender:LTR
Submission time:2016-05-28 13:32:50 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.06 sdetails
#2ACCEPTED0.05 sdetails
#30.10 sdetails
#40.06 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:17:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < s.size(); ++i) {
                              ^
input/code.cpp:50:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while (Hi < H.size() && H[Hi] < i) Hi++;
                       ^
input/code.cpp:53:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while (Ti < T.size() && T[Ti] < i) Ti++;
                       ^
input/code.cpp:77:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int iI = 0; iI < (Iok.size() - 1); ++iI) {
                                        ^

Code

#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <set>

int main()
{
	int t;
	std::cin >> t;
	for (int ti = 0; ti < t; ++ti) {
		std::string s;
		std::cin >> s;
		std::vector<int> H;
		std::vector<int> I;
		std::vector<int> T;
		for (int i = 0; i < s.size(); ++i) {
			auto c = s[i];
			if (c == 'H') H.push_back(i);
			if (c == 'I') I.push_back(i);
			if (c == 'T') T.push_back(i);
		}

		if (H.size() == 0 || T.size() == 0) {
			std::cout << 0 << std::endl;
			continue;
		}

		int Hmin = H[0];
		int Tmax = T[T.size() - 1];
		std::vector<int> Iok;
		for (auto i : I) {
			if (i < Hmin) continue;
			if (i > Tmax) break;
			Iok.push_back(i);
		}

		if (Iok.size() < 2) {
			std::cout << 0 << std::endl;
			continue;
		}

		std::vector<int> Hbefore(Iok.size(), 0);
		std::vector<int> Tafter(Iok.size(), 0);

		int Hi = 0; // num of H values before this I
		int Ti = 0; // num of T values before this I
		for (size_t iI = 0; iI < Iok.size(); ++iI) {
			int i = Iok[iI];
			while (Hi < H.size() && H[Hi] < i) Hi++;
			Hbefore[iI] = Hi;

			while (Ti < T.size() && T[Ti] < i) Ti++;
			Tafter[iI] = T.size() - Ti;
		}

		std::vector<int> TafterCumu(Iok.size());
		TafterCumu[Iok.size() - 1] = Tafter[Iok.size() - 1];
		for (int iI = Iok.size() - 2; iI >= 0; --iI) {
			TafterCumu[iI] = Tafter[iI] + TafterCumu[iI+1];
		}

		// std::cerr << "Hbefore:";
		// for (auto h : Hbefore) std::cerr << " " << h;
		// std::cerr << std::endl;
		// std::cerr << "Iok:";
		// for (auto h : Iok) std::cerr << " " << h;
		// std::cerr << std::endl;
		// std::cerr << "Tafter:";
		// for (auto h : Tafter) std::cerr << " " << h;
		// std::cerr << std::endl;
		// std::cerr << "TafterCumu:";
		// for (auto h : TafterCumu) std::cerr << " " << h;
		// std::cerr << std::endl;

		long long count = 0;
		for (int iI = 0; iI < (Iok.size() - 1); ++iI) {
			count += Hbefore[iI] * TafterCumu[iI + 1];
		}

		std::cout << count << std::endl;
	}
}

Test details

Test 1

Verdict: ACCEPTED

input
100
IIITIIIHITHTHIIITIII
HIHIIIIIIHIIITHIIIII
ITTIIIITIIIIIIITIIIT
IITHITITIHHIITTTIIII
...

correct output
12
84
0
37
96
...

user output
12
84
0
37
96
...

Test 2

Verdict: ACCEPTED

input
100
TIIHHITTITITIHTHIIIITHIHHIIHTI...

correct output
606723862
621369559
655243897
550750615
717769300
...

user output
606723862
621369559
655243897
550750615
717769300
...

Test 3

Verdict:

input
10
TTHTHHTIIIIIITHIIHIITITTITTIIH...

correct output
64668032062669502
66159978956790306
65755072918424640
64408596558953628
65238005187079543
...

user output
766776132286
-264206476766
-489836278720
146001673372
-366195774089
...

Test 4

Verdict:

input
3
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH...

correct output
781234375000000000
4999750003
0

user output
5908923904
4999750003
0