66892023-12-16 18:45:06111DNScpp17Accepted 40/4012ms10564 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double

#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifdef CB
	freopen("be2.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	string S;
	cin >> S;
	int N = S.size();
	int ans = 0;
	for (char c : {'A', 'C', 'G', 'T'}) {
		vector<int> m(N * 2 + 1, -1);
		int a = N;
		for (int i = 0; i < N; i++) {
			a += (S[i] == c) * 2 - 1;
			if (a > 0) {
				if (m[a] != -1) {
					ans = max(ans, i - m[a]);
				}
				else {
					m[a] = i;
				}
			}
		}
		if (a >= N) {
			ans = N;
		}
	}
	cout << ans << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1700 KiB
2Accepted0/012ms8880 KiB
3Accepted2/23ms2072 KiB
4Accepted2/23ms2284 KiB
5Accepted2/23ms2496 KiB
6Accepted2/23ms2720 KiB
7Accepted2/23ms2824 KiB
8Accepted4/44ms4812 KiB
9Accepted4/44ms6252 KiB
10Accepted4/46ms7128 KiB
11Accepted4/47ms8244 KiB
12Accepted4/47ms8468 KiB
13Accepted5/58ms9740 KiB
14Accepted5/58ms10564 KiB