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

Code

#include <bits/stdc++.h>
using namespace std;
#define int long long
string to_string(string s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
const int N = 1e5 + 5;
const string S = "HIIT";
string s;
int n;
int dp[N][5];
void solve() {
cin >> s;
n = s.size();
s = '_' + s;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= 4; j++) {
dp[i][j] = 0;
}
}
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++) {
if (s[i + 1] == S[j]) {
// could take
dp[i + 1][j + 1] += dp[i][j];
}
dp[i + 1][j] += dp[i][j];
}
}
int ans = 0;
for (int i = 0; i <= n; i++) {
ans += dp[i][4];
}
// for (int i = 0; i <= n; i++) {
// for (int j = 0; j <= 4; j++) {
// cerr << dp[i][j] << ' ';
// }
// cerr << '\n';
// }
cout << ans << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
solve();
}
}

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