CSES - HIIT Open 2016 - Results
Submission details
Task:HIIT remains
Sender:Spitfire
Submission time:2016-05-28 13:44:45 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.06 sdetails
#3--details
#4--details

Code

#include <iostream>
#include <string>
#include <vector>
#include <cinttypes>
#include <cstdint>

uint64_t arr[100000];

void precalc()
{
  uint64_t sum = 0;
  for (size_t i = 0; i < 100000; i++) {
    sum += i;
    arr[i] = sum;
  }
}


int main()
{
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(0);

	unsigned int n;
	std::cin >> n;

	precalc();

	std::vector<size_t> ongoing;
	ongoing.reserve(100000);

	std::cin.get();

	char c;

	for (size_t i = 0; i < n; i++) {
	  ongoing.clear();
	  uint64_t sum = 0;

	  std::cin.get(c);
	  while (c != '\n' && !std::cin.eof()) {

	    switch (c) {
	    case 'H':
	      ongoing.push_back(0);
	      break;
	    case 'I':
	      for (auto & elem: ongoing) {
		++elem;
	      }
	      break;
	    case 'T':
	      for (const auto & elem: ongoing) {
		if (elem >= 2) {
		  sum += arr[elem - 1];
		}
	      }
	      break;
	    }
	    std::cin.get(c);
	  }

	  std::cout << sum << std::endl;
	}


	return 0;
}

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
(empty)

Test 4

Verdict:

input
3
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH...

correct output
781234375000000000
4999750003
0

user output
(empty)