CSES - HIIT Open 2016 - Results
Submission details
Task:HIIT remains
Sender:ContinuedLife
Submission time:2016-05-28 16:08:31 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.11 sdetails
#2ACCEPTED0.10 sdetails
#30.14 sdetails
#40.07 sdetails

Compiler report

input/code.cpp: In function 'int solve(int, std::string&, int)':
input/code.cpp:9:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(start == input.size()) return 0;
                         ^

Code

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(6);

using namespace std;
#define HIIT 15
int table[20][100000];

int solve(int curr, string& input, int start){
	if(start == input.size())	return 0;
	if(table[curr][start])	return table[curr][start];
	
	int last = 1;
	for( ; last < 4; ++last){	
		int temp = (1 << last)& curr;
		//cout << temp << endl;
		if(temp)	
			break;
	}

	int ans = 0;
	switch(last){
		case 1:
			if(input[start] == 'T')	 ans += 1;
			ans += solve(curr, input, start + 1);
			break;
		case 2: 
			if(input[start] == 'I')	 ans += solve(curr | (1<<1), input, start + 1);
			ans += solve(curr, input, start+1);
			break;
		case 3:
			if(input[start] == 'I')	 ans += solve(curr | (1<<2), input, start + 1);
			ans += solve(curr, input, start+1);
			break;
		case 4:
			if(input[start] == 'H')	 ans += solve(curr | (1<<3), input, start + 1);
			ans += solve(curr, input, start+1);
			break;
	}
	table[curr][start] = ans;
	return ans;
}

int main(){ _
	int TC;	cin >> TC;	
	while(TC--){
		string input, str;
		cin >> input;
		for(int i = 0; i < int(input.size()); ++i){
			if(input[i] == 'H' || input[i] == 'I' || input[i] == 'T'){
				str.push_back(input[i]);
//				cout << "get here" << endl;
			}
		}

		memset(table, 0, sizeof table);
		int curr = 0;
		cout << solve(curr, str, 0) << 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
-2023013698
2081495586
-210006976
-27214692
-1123553929
...

Test 4

Verdict:

input
3
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH...

correct output
781234375000000000
4999750003
0

user output
1613956608
704782707
0