246692026-02-13 12:20:26algoproDNScpp17Accepted 40/4074ms10036 KiB
// UUID: 98b8d4d9-8939-41f5-abb6-8765fd2353a0
#include <bits/stdc++.h>
using namespace std;

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    int res = 0;
    for (char letter : {'C', 'T', 'A', 'G'}) {
        unordered_map<int, int> map;
        int pref = 0;
        map[0] = -1;
        for (int i = 0; i < n; i++) {
            if (letter == s[i]) pref++;
            else pref--;
            if (pref >= 0) {
                res = max(res, i+1);
                continue;
            }

            if (map.find(pref) == map.end()) {
                map[pref] = i;
            }else res = max(res, i - map[pref]);
        }
    }
    cout << res;
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/01ms496 KiB
2Accepted0/074ms5932 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted4/417ms1788 KiB
9Accepted4/428ms2800 KiB
10Accepted4/435ms3044 KiB
11Accepted4/446ms3756 KiB
12Accepted4/450ms6508 KiB
13Accepted5/567ms10032 KiB
14Accepted5/574ms10036 KiB