304588: CF873B. Balanced Substring
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Balanced Substring
题意翻译
给出一个长度为 $n$ 的 $01$ 串,其中含有相同 $0,1$ 个数的子串被称为“平衡串”,问最长的平衡串的长度。题目描述
You are given a string $ s $ consisting only of characters 0 and 1. A substring $ [l,r] $ of $ s $ is a string $ s_{l}s_{l+1}s_{l+2}...\ s_{r} $ , and its length equals to $ r-l+1 $ . A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to determine the length of the longest balanced substring of $ s $ .输入输出格式
输入格式
The first line contains $ n $ ( $ 1<=n<=100000 $ ) — the number of characters in $ s $ . The second line contains a string $ s $ consisting of exactly $ n $ characters. Only characters 0 and 1 can appear in $ s $ .
输出格式
If there is no non-empty balanced substring in $ s $ , print 0. Otherwise, print the length of the longest balanced substring.
输入输出样例
输入样例 #1
8
11010111
输出样例 #1
4
输入样例 #2
3
111
输出样例 #2
0