CSES - Practice Contest 2024 - Results
Submission details
Task:HIIT remains
Sender:hefapa_aachen
Submission time:2024-09-28 13:11:14 +0300
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#20.00 sdetails
#30.01 sdetails
#40.01 sdetails

Code

// ~/.vim/cpp_template.cpp
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i,a,b) for (int i = a; i < b; i++)

// Type Aliases for 1D and 2D vectors with initialization
#define vi(n, val) vector<int>(n, val) // 1D vector of ints with size n, initialized to val
#define vll(n, val) vector<long long>(n, val) // 1D vector of long longs with size n, initialized to val
#define ll long long
#define vvi(n, m, val) vector<vector<int>>(n, vector<int>(m, val)) // 2D vector of ints (n x m), initialized to val
#define vvll(n, m, val) vector<vector<long long>>(n, vector<long long>(m, val)) // 2D vector of long longs (n x m), initialized to val


using namespace std;

template <typename T>
void pV(const std::vector<T>& vec, const std::string& label = "Vector") {
    std::cout << label << ": [ ";
    for (const auto& elem : vec) {
        std::cout << elem << " ";
    }
    std::cout << "]" << std::endl;
}


using namespace std;


void dfs(int s, vector<bool> *visited, vector<int> (*adj)[]) {
    if ((*visited)[s]) return;
    (*visited)[s] = true;
    // process node s


    for (auto u: (*adj)[s]) {
        dfs(u, visited, adj);
    }
}
/*
vector<int> adj[N];                                                          
vector<bool> visited(N, false);
int u, v;
for(int i = 0; i < M;i++){
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
}
*/

long long fact(int n){
    if(n==0) return 1;
    long long res = 1;
    REP(i, 2, n+1){
        res = res*i;
    }
    return res;
}

long long nck(int n, int k){
    return fact(n) / (fact(k) *fact(n-k));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // Your code starts here
    int t;
    cin >> t;
    REP(i, 0, t){
        string s;
        cin >> s;
        int n;
        n = s.size();

        vector<int> is(n, 0);
        long long I= 0;
        REP(i, 0, n){
            if(i > 0){
                is[i] = is[i-1];
            }
            if(s[i] == 'I'){
                is[i]++;
                I++;
            }
        }
        //int l = 0, r = n-1;
        long long res = 0;
        //while(l<r-2){
        REP(l, 0, n){
           for(int r=n-1; r >=l+2;r--){

                /*
                while(s[l] != 'H' && l < r-2) l++;
                while(s[r] != 'T' && l < r-2) r--;
                */
                if(s[l]!= 'H' || s[r] != 'T') continue;
                int n_is = is[r-1] - is[l];
                res+= nck(n_is, 2);
            }

        }
        cout << res << 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
...
Truncated

Test 2

Verdict:

input
100
TIIHHITTITITIHTHIIIITHIHHIIHTI...

correct output
606723862
621369559
655243897
550750615
717769300
...

user output
(empty)

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)