1102021-01-12 18:09:19Tiszay DávidDNScpp11Time limit exceeded 22/40365ms27300 KiB
#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define flog(n) 31-__builtin_clz((n))
#define clog(n) 32-__builtin_clz((n)-1)
#define fori(i,a,b) for(long long int i=(a);i<=(b);i++)
#define forib(i,a,b) for(long long int i=(a);i>=(b);i--)
using ll=long long; using pi=pair<int,int>; using vi=vector<int>; using vl=vector<ll>;

string n;
ll maxi = 0;

void max_length(char t){
    map<ll ,ll> m;
    map<ll, bool> since;
    m[0] = -1;
    ll curr = 0;
    fori(i, 0, n.length() - 1){
        if (n[i] == t){
            curr++;
        } else {
            curr--;
        }
        if (since[curr] == false){
            since[curr] = true;
            m[curr] = i;
        }
        if (curr >= 0){
            maxi = max(maxi, i + 1);
        } else {
            maxi = max(maxi, i - m[curr]);
        }
    }
}


void solve(){
    cin >> n;
    max_length('A');
    max_length('T');
    max_length('G');
    max_length('C');
    cout << maxi << endl;
}
int main() {
  if(true){ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
  solve();
}
SubtaskSumTestVerdictTimeMemory
base22/40
1Accepted0/02ms1752 KiB
2Time limit exceeded0/0365ms17556 KiB
3Accepted2/21ms2040 KiB
4Accepted2/21ms2048 KiB
5Accepted2/21ms2052 KiB
6Accepted2/21ms2096 KiB
7Accepted2/22ms2144 KiB
8Accepted4/4101ms10288 KiB
9Accepted4/4190ms15552 KiB
10Accepted4/4254ms17380 KiB
11Time limit exceeded0/4354ms22788 KiB
12Time limit exceeded0/4326ms20604 KiB
13Time limit exceeded0/5317ms24560 KiB
14Time limit exceeded0/5317ms27300 KiB