206912026-01-08 17:45:01algoproDNScpp17Accepted 40/4087ms10096 KiB
// UUID: 7983b1f9-0879-4878-b021-41d4b4b85fd1
#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'}){
		unordered_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/01ms316 KiB
2Accepted0/082ms5944 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms416 KiB
7Accepted2/21ms316 KiB
8Accepted4/420ms1744 KiB
9Accepted4/434ms2704 KiB
10Accepted4/439ms3052 KiB
11Accepted4/452ms3688 KiB
12Accepted4/459ms6440 KiB
13Accepted5/579ms10096 KiB
14Accepted5/587ms9904 KiB