Code Submission Evaluation System Login

CSES - HIIT Open 2016

HIIT Open 2016

Contest start:2016-05-28 11:00:00
Contest end:2016-05-28 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2016-05-28 13:44:45
2016-05-28 13:33:32
2016-05-28 13:16:08
Task:HIIT remains
Sender:Spitfire
Submission time:2016-05-28 13:44:45
Status:READY
Result:TIME LIMIT EXCEEDED

Show test data

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;
}