8852022-01-25 09:39:54kidesoDNScpp14Time limit exceeded 18/40398ms6336 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;

int kar(char c) {
    if (c == 'A') return 1;
    if (c == 'C') return 2;
    if (c == 'G') return 3;
    return 4;
}

int main()
{
    cin >> s;
    N = s.length();
    vector <adat> x(N + 1);

    maxi = 1;

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

        x[i] = x[i - 1];
        x[i].sz[k]++;
        x[i].sz[0] = max(x[i].sz[0], x[i].sz[k]);
    }

    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);
    }

    cout << maxi;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base18/40
1Accepted0/02ms1740 KiB
2Time limit exceeded0/0386ms5360 KiB
3Accepted2/21ms2040 KiB
4Accepted2/21ms2048 KiB
5Accepted2/21ms2056 KiB
6Accepted2/21ms2064 KiB
7Accepted2/22ms2084 KiB
8Accepted4/464ms3956 KiB
9Accepted4/4155ms5572 KiB
10Time limit exceeded0/4386ms3544 KiB
11Time limit exceeded0/4398ms4272 KiB
12Time limit exceeded0/4397ms4920 KiB
13Time limit exceeded0/5391ms5644 KiB
14Time limit exceeded0/5393ms6336 KiB