EMTY3 - Can You Make It Empty 3
Let us introduce an algorithm with a function CanEmpty() which takes a string P as a parameter and return TRUE if it is possible to make P empty, otherwise return FALSE.
String P consists of only 0 and 1. The pseudo-code implementation of CanEmpty() function is as follows.
bool CanEmpty(String P) { while (P has at least one substring 100) { Chose any one substring 100 in P and delete it. } if (P is empty) return TRUE; else return FALSE; }
Now you are given a string S consisting of 0 and 1, you have to find the length of longest substring of S that can be made empty applying CanEmpty() algorithm.
As for example, let S=1011100000100
S has only two sub-strings (bold) which can be made empty applying CanEmpty() algorithm.
The first substring will have the delete- sequence in CanEmpty() function :
110000->100->empty
The second substring will have the delete-sequence in CanEmpty() function:
100->empty
The length of first substring is 6 and second is 3. So, the required answer is 6.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case contains a string S. The size of string is at most 200000.
Output
For each test case, print the case number and required answer.
Sample Input |
Output for Sample Input |
2 |
Case 1: 6 |
Problem Setter: Md Abdul Alim, Dept. of Computer Science, Bangladesh University of Business & Technology
hide comments
Sushovan Sen:
2024-02-17 07:11:06
@nightwolf_9197
|
|
nightwolf_9197:
2019-03-25 08:29:56
@Md Abdul Alim can you please tell me where my code goes wrong as it passes on all of my test cases.
|
|
iharsh234:
2016-07-31 12:01:50
0.09 without fast io |
|
hodobox:
2015-08-27 20:13:11
Nice problem :)
|
|
:.Mohib.::
2015-07-08 23:56:00
@lakshman I also.... did it in O(N)..0.05s :)
|
|
[Lakshman]:
2015-06-28 17:51:28
@Mohib I did this in O(N). |
|
:.Mohib.::
2015-06-26 13:04:45
What complexity expected??? |
|
Diksha Jaiswal:
2014-12-30 12:09:07
@ivar.raknahs it is 15.
|
|
ivar.raknahs:
2014-12-21 12:15:39
@Md Abdul Alim: what should be the o/p of 100100111000000
|
Added by: | Alim |
Date: | 2014-10-08 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: GOSU |
Resource: | Own Problem |