8872022-01-25 10:14:09kidesoDNScpp14Time limit exceeded 6/40398ms13176 KiB
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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 <vector<int>> x(N + 1, vector <int>(5, 0));

    maxi = 1;

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

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

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

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

        while (!jo){
            p = x[i][0] - x[k - 1][0];
            if (2 * p >= i - k + 1){
                jo = true;
                break;
            }


            k += 2;
        }

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

    cout << maxi;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/40
1Accepted0/01ms1736 KiB
2Time limit exceeded0/0398ms12400 KiB
3Wrong answer0/21ms2032 KiB
4Wrong answer0/21ms2044 KiB
5Accepted2/21ms2052 KiB
6Wrong answer0/21ms2076 KiB
7Wrong answer0/21ms2112 KiB
8Accepted4/439ms7588 KiB
9Wrong answer0/4122ms10964 KiB
10Time limit exceeded0/4397ms6972 KiB
11Time limit exceeded0/4381ms8756 KiB
12Time limit exceeded0/4384ms10024 KiB
13Time limit exceeded0/5391ms11784 KiB
14Time limit exceeded0/5397ms13176 KiB