CSES - Practice Contest 2024 - Results
Submission details
Task:HIIT remains
Sender:GenericTeamname
Submission time:2024-09-28 12:54:24 +0300
Language:C++ (C++11)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.03 sdetails
#4ACCEPTED0.01 sdetails

Compiler report

input/code.cpp: In function 'long long int calc(std::string)':
input/code.cpp:34:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int i = 0; i < s.length(); i++) {
      |                     ~~^~~~~~~~~~~~

Code

#include <bits/stdc++.h>

using namespace std;
#define int long long

// g++ <filename>.cpp -g -Wall -Wextra -DDEBUG -o <executable>

// copied from: https://codeforces.com/blog/entry/79024
// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===

int calc(string s) {

    vector<int> dp(4,0); // store counts for H, HI, HII, HIIT

    for (int i = 0; i < s.length(); i++) {

        if (s[i] == 'H') {
            dp[0]++;
        } 
        else if (s[i] == 'I') {
            if (dp[1] > 0) {
                dp[2] += dp[1];
            } 
            if (dp[0] > 0) {
                dp[1] += dp[0];
            }
        } 
        else if (s[i] == 'T') {
            if (dp[2] > 0) {
                dp[3] += dp[2];
            }
        }
    }

    return dp[3];
}

signed main() {
    
    int t;
    cin >> t;
    
    for (int i = 0; i < t; i++) {
        string s;
        cin >> s;

        cout << calc(s) << "\n";
    }

    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
...
Truncated

Test 2

Verdict: ACCEPTED

input
100
TIIHHITTITITIHTHIIIITHIHHIIHTI...

correct output
606723862
621369559
655243897
550750615
717769300
...

user output
606723862
621369559
655243897
550750615
717769300
...
Truncated

Test 3

Verdict: ACCEPTED

input
10
TTHTHHTIIIIIITHIIHIITITTITTIIH...

correct output
64668032062669502
66159978956790306
65755072918424640
64408596558953628
65238005187079543
...

user output
64668032062669502
66159978956790306
65755072918424640
64408596558953628
65238005187079543
...
Truncated

Test 4

Verdict: ACCEPTED

input
3
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH...

correct output
781234375000000000
4999750003
0

user output
781234375000000000
4999750003
0