14422022-10-10 13:55:44AbbenceDNScpp17Accepted 40/408ms5348 KiB
#include <bits/stdc++.h>

using namespace std;

// megadott hivatalos megoldás

int main()
{
    const char acgt[4] = {'A', 'C', 'G', 'T'};

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie();

    string dns; cin >> dns;
    int n = dns.length();
    int ans = 0;

    for (char c : acgt)
    {
        vector<int> first_occur(n + 1, -1);
        int cnt = 0;
        for (int i = 0; i < n; ++i)
        {
            cnt += dns[i] == c ? 1 : -1;
            if (cnt >= 0)
                ans = max(ans, i + 1);
            else
            {
                if (first_occur[-cnt] == -1)
                    first_occur[-cnt] = i;
                else
                    ans = max(ans, i - first_occur[-cnt]);
            }
        }
    }

    cout << ans << "\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1828 KiB
2Accepted0/08ms4288 KiB
3Accepted2/22ms2360 KiB
4Accepted2/22ms2256 KiB
5Accepted2/22ms2292 KiB
6Accepted2/22ms2420 KiB
7Accepted2/22ms2496 KiB
8Accepted4/43ms3296 KiB
9Accepted4/44ms3920 KiB
10Accepted4/44ms4536 KiB
11Accepted4/44ms4580 KiB
12Accepted4/44ms4672 KiB
13Accepted5/54ms4932 KiB
14Accepted5/54ms5348 KiB