8812022-01-25 09:24:15kidesoDNScpp11Runtime error 0/404ms2652 KiB
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

struct adat{
    int sz[5] = { 0,0,0,0,0 };
};

string s;
int k, maxi, i, N, maxi1, p;
bool jo;
map <char, int> kar;

int main()
{
    scanf("%s", &s);
    N = s.size();
    vector <adat> x(N + 1);

    kar['A'] = 1;
    kar['C'] = 2;
    kar['G'] = 3;
    kar['T'] = 4;

    maxi = 1;

    for (i = 1; i <= N; ++i){
        k = kar[s[i - 1]];

        for (int j = 1; j <= 4; ++j){
            if (j == k) x[i].sz[j] = x[i - 1].sz[j] + 1;
            else x[i].sz[j] = x[i - 1].sz[j];

            x[i].sz[0] = max(x[i].sz[0], x[i].sz[j]);
        }
    }

    for (i = 2; i <= N; ++i){
        maxi1 = x[i].sz[0];

        k = max(1, i - 2 * maxi1 + 1);
        jo = false;

        while (!jo){
            for (int j = 1; j <= 4; ++j){
                p = x[i].sz[j] - x[k - 1].sz[j];
                if (2 * p >= i - k + 1){
                    jo = true;
                    break;
                }
            }

            k += 2;
        }

        k -= 2;
        maxi = max(maxi, i - k + 1);
    }

    printf("%d", maxi);
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Runtime error0/02ms1772 KiB
2Runtime error0/01ms1904 KiB
3Runtime error0/22ms2648 KiB
4Runtime error0/24ms2288 KiB
5Runtime error0/23ms2308 KiB
6Runtime error0/23ms2304 KiB
7Runtime error0/23ms2312 KiB
8Runtime error0/41ms2088 KiB
9Runtime error0/41ms2140 KiB
10Runtime error0/41ms2220 KiB
11Runtime error0/41ms2320 KiB
12Runtime error0/41ms2432 KiB
13Runtime error0/51ms2548 KiB
14Runtime error0/51ms2652 KiB