179502025-09-23 21:46:46ubormaciDNS szakaszok száma (75 pont)cpp17Accepted 75/7554ms8964 KiB
#include <iostream>
#include <algorithm> // for sort, mainly
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint> // for int64_t, int32_t, etc
#include <queue>
#include <stack>
#include <deque>
#include <numeric> // gcd, lcm
#include <fstream>
#include <bitset> // for bitset
#include <iomanip>
#include <cassert> // for set with custom ordering
#include <type_traits> // for set with custom ordering
#include <utility> // for swap, forward, etc
using namespace std;

#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
//#pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2","fma")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*
 *
 * notes:
 *
 * int64_t
 * stoi(string s) -> string to int
 * to_string() -> int (or else) to string
 *
 * vector declaration:
 * vector<ll> v(n, 0)
 * vector<vector<ll>> v(n, vector<ll>(n, 0));
 *
 * {if statement} ? {truth value} : {false value}
 *
 * set lower bound/upper bound:
 * 	// . . . m1 . . . d . . . . m2
 *    auto m1_it = b.lower_bound(d);
 *    advance(m1_it, -1);
 *    m1 = *m1_it;
 *	m2 = *b.upper_bound(d);
 *
 * #ifdef LOCAL
 *    freopen("in.txt","r",stdin);
 *    freopen("out.txt","w",stdout);
 * #endif
 *
 * constexpr auto lcm(auto x, auto... xs)
 * {
 *	return ((x = std::lcm(x, xs)), ...);
 * }
 *
 * std::gcd(int a, int b)
 *
 * cout << setprecision(n);
 *
 * set with custom ordering
 * set<ll, decltype(&cmp)> qu(cmp);
 *
 */

typedef int64_t ll;

void solve() {

    ll n;
    string s;

    cin >> n >> s;

    // minden a-ra binarisan hogy melyik a legelso t, amelyik elott mar van egy g

    set<ll> g;
    set<ll> t;

    map<ll,ll> tctr;

    for(ll i = 0; i < n; i++) {
        if(s[i] == 'G') {
            g.insert(i);
        }
        if(s[i] == 'T') {
            t.insert(i);
        }
    }

    ll j = 1;
    for(const auto & x : t) {
        tctr[x] = j;
        j++;
    }

    ll ans = 0;

    ll totalt = t.size();
    
    if(g.size() == 0 || t.size() == 0) {
        cout << "0";
        return;
    } 

    for(ll i = 0; i < n; i++) {
        if(s[i] == 'A') {

            //cerr << "\ni=" << i;

            if(i >= *g.rbegin()) {
                break;
            }
            ll fg = *g.upper_bound(i); // first g position
            if(fg >= *t.rbegin()) {
                break;
            }

            ll ft = *t.upper_bound(fg);
            // we've got the position of the first t

            //cerr << "\nfg=" << fg;
            //cerr << "\nft=" << ft;

            //cerr << "\nft is t no. " << tctr[ft];

            ll badt = tctr[ft] - 1;

            ans += totalt - badt;

        }
    }

    cout << ans;


}

int main()
{
    std::ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
    //cout.tie(nullptr);

    solve();

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/01ms316 KiB
2Accepted0/027ms4400 KiB
3Accepted3/31ms320 KiB
4Accepted4/41ms316 KiB
5Accepted4/41ms316 KiB
6Accepted4/41ms316 KiB
7Accepted4/41ms316 KiB
8Accepted3/31ms316 KiB
9Accepted3/31ms508 KiB
10Accepted4/41ms316 KiB
11Accepted4/41ms316 KiB
12Accepted4/41ms316 KiB
13Accepted4/41ms316 KiB
14Accepted4/41ms316 KiB
15Accepted3/325ms4184 KiB
16Accepted4/421ms3160 KiB
17Accepted4/424ms4984 KiB
18Accepted4/443ms7172 KiB
19Accepted4/417ms2356 KiB
20Accepted4/454ms8964 KiB
21Accepted3/339ms5940 KiB
22Accepted4/439ms5684 KiB