206902026-01-08 17:44:21algoproDNScpp17Time limit exceeded 40/40314ms9924 KiB
// UUID: 09081356-5144-433e-ac6e-36c7852131a8
#include <bits/stdc++.h>
using namespace std;

int main() {
	string s; cin >> s;
	int n=s.size();
	int ans=0;
	for(char c : {'A', 'C', 'G', 'T'}){
		map<int, int> pos;
		pos[0]=-1;
		int runningTotal=0;
		for(int i=0;i<n;i++){
			if(i<n) runningTotal+=(2*(c==s[i])-1);
			if(pos.count(runningTotal)==0) pos[runningTotal]=i;
			//printf("%d-%d (%c %d)\n", i, pos[runningTotal], c, runningTotal);
			ans=max(ans, i-pos[runningTotal]);
			if(0<runningTotal) ans=max(ans, i+1);
		}
	}
	cout << ans;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/01ms508 KiB
2Time limit exceeded0/0314ms6596 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted4/452ms2004 KiB
9Accepted4/496ms2848 KiB
10Accepted4/4122ms3100 KiB
11Accepted4/4170ms4144 KiB
12Accepted4/4180ms7364 KiB
13Accepted5/5228ms8900 KiB
14Accepted5/5250ms9924 KiB