2025区赛 平衡 AB 串(abstring)
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
【题目描述】
有一个只包含字符 'A' 和 'B' 的字符串。
我们把“某一段连续子串中 'A' 的个数等于 'B' 的个数”称为一段“平衡子串”。
请你找出整个字符串中最长的平衡子串长度。
例如:
"AABBAA" 中:
子串 "AABB" 有 2 个 A 和 2 个 B,长度 4;
子串 "ABBA"、"BBAA" 也平衡,长度 4;
最长平衡子串长度为 4。
【输入格式】
一行字符串 s,长度 1 ≤ |s| ≤ 200000,保证只包含 'A' 和 'B'。
【数据范围】
对于 30% 的数据:1 ≤ |s| ≤ 2000。
对于 60% 的数据:1 ≤ |s| ≤ 50000。
对于 100% 的数据:1 ≤ |s| ≤ 200000
【输出格式】
输出一个整数,为最长平衡子串的长度。
【输入样例1】
AABBAA
【输出样例1】
4
【样例解释】
无
2025年区赛
- Status
- Done
- Rule
- ACM/ICPC
- Problem
- 6
- Start at
- 2026-1-13 21:00
- End at
- 2026-4-7 5:00
- Duration
- 2000 hour(s)
- Host
- Partic.
- 16