23622023-01-11 12:42:28sztomiDNScpp11Wrong answer 26/40193ms15024 KiB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1 << 17;
vector<int> fa;


int bal_ind(int x){
    return x*2;
}

int jobb_ind(int x){
    return x*2+1;
}

int hozzaad(int akt, int bal, int jobb, int cel, int ertek){
    if(jobb < cel || cel < bal) return -1;
    if(jobb == bal){
        fa[akt] = max(fa[akt], ertek);
        return fa[akt];
    }

    int kozep = (bal + jobb) / 2;
    if(cel <= kozep){
        fa[akt] = max(fa[akt], hozzaad(bal_ind(akt), bal, kozep, cel, ertek));
    }
    else{
        fa[akt] = max(fa[akt], hozzaad(jobb_ind(akt), kozep+1, jobb, cel, ertek));
    }
    return fa[akt];
}

int lekerdez(int akt, int bal, int jobb, int k_bal, int k_jobb){
    if(k_bal > k_jobb) return -1;
    if(jobb < k_bal || k_jobb < bal) return -1;
    if(bal == jobb){
        return fa[akt];
    }
    if(k_bal == bal && k_jobb == jobb){
        return fa[akt];
    }
    if(fa[akt] == -1){
        return fa[akt];
    }
    int kozep = (bal + jobb) / 2;
    int ki = lekerdez(bal_ind(akt), bal, kozep, k_bal, min(kozep, k_jobb));
    ki = max(ki, lekerdez(jobb_ind(akt), kozep+1, jobb, max(k_bal, kozep+1), k_jobb));
    return ki;
}




int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin>> s;
    int n = s.size();
    string betuk = "ACGT";
    map<char, vector<int>> db;
    vector<int> ideigl(n+1, 0);
    int prev;
    for(char c : betuk){
        prev = 0;
        for(int i = 0; i < n; i++){
            if(s[i] == c){
                ideigl[i+1] = ++prev;
            }
            else{
                ideigl[i+1] = --prev;
            }
        }
        db.insert({c, ideigl});
    }

    int ki = 1;
    int temp;
    fa.assign(2*MAXN, -1);
    for(char c : betuk){
        vector<int> v = db[c];
        for(int i = n; i > 0; i--){
            hozzaad(1, 0, MAXN-1, n+v[i], i);
            temp = lekerdez(1, 0, MAXN-1, n+v[i-1], 400000);
            ki = max(ki, temp - i + 1);
        }
        for(int& x : fa){
            x = -1;
        }
    }

    cout << ki << "\n";
}
SubtaskSumTestVerdictTimeMemory
base26/40
1Accepted0/04ms3620 KiB
2Wrong answer0/0120ms13756 KiB
3Accepted2/23ms4060 KiB
4Accepted2/23ms4372 KiB
5Accepted2/23ms4312 KiB
6Accepted2/24ms4720 KiB
7Accepted2/24ms4560 KiB
8Accepted4/476ms7344 KiB
9Accepted4/4119ms9072 KiB
10Accepted4/4155ms10060 KiB
11Accepted4/4193ms11576 KiB
12Wrong answer0/4115ms12552 KiB
13Wrong answer0/5118ms14404 KiB
14Wrong answer0/5116ms15024 KiB