Problem Statement
We are in a distant future. After the downfall of mankind, the Earth is now ruled by fairies. The "Turing game Online" website is hot among fairies right now. On this website, everyone can play the programming puzzle "Turing game".
Fairies love powers of 5, that is, the numbers 1, 5, 25, 125, 625, and so on. In the Turing game, the player is given a string of bits (zeros and ones). The ideal situation is when the string is represents a power of 5 in binary, with no leading zeros. If that is not the case, the fairy player tries to cut the given string into pieces, each piece being a binary representation of a power of 5, with no leading zeros. Of course, it may be the case that even this is impossible. In that case, the fairy player becomes depressed, and bad things happen when a fairy gets depressed. You, as one of the surviving humans, are in charge of checking the bit strings to prevent the bad things from happening.
You are given a
Definition
- Class:
- CuttingBitString
- Method:
- getmin
- Parameters:
- String
- Returns:
- int
- Method signature:
- int getmin(String S)
- (be sure your method is public)
Constraints
- S will contain between 1 and 50 characters, inclusive.
- Each character in S will be either '0' or '1'.
Examples
"101101101"
Returns: 3
We can split the given string into three "101"s. Note that "101" is 5 in binary.
"1111101"
Returns: 1
"1111101" is 5^3.
"00000"
Returns: -1
0 is not a power of 5.
"110011011"
Returns: 3
Split it into "11001", "101" and "1".
"1000101011"
Returns: -1
"111011100110101100101110111"
Returns: 5
"1101100011010111001001101011011100010111011110101"
Returns: 1
"0101"
Returns: -1
"1001"
Returns: -1
"11111111111111111111111111111111111111111111111111"
Returns: 50
"10111001110011"
Returns: 4
"10011100011110011100111110100001001110011"
Returns: 7
"10111110101111000011111010000100111110100001001101"
Returns: 4
"11101111011011111101110011101101101111011101101111"
Returns: 22
"11111101111111011111011101"
Returns: 10
"1011111110111111011111101111111111101111110111"
Returns: 14
"11111011111101111110111111011111101111110111111011"
Returns: 8
"11111011111111101111111101111111101111110111111111"
Returns: 20
"11111011111101111111011111101111111111111101111111"
Returns: 20
"11001110001"
Returns: 2
"110011000100101101"
Returns: 2
"111110100001001"
Returns: 2
"101111101"
Returns: 5
"11001110001111101"
Returns: 6
"0"
Returns: -1
"1"
Returns: 1
"00"
Returns: -1
"10"
Returns: -1
"01"
Returns: -1
"11"
Returns: 2
"000"
Returns: -1
"100"
Returns: -1
"010"
Returns: -1
"110"
Returns: -1
"001"
Returns: -1
"101"
Returns: 1
"011"
Returns: -1
"111"
Returns: 3
"00000000000000000000000000000000000000000000000000"
Returns: -1
"101101101101101101101101101101101101101101101101"
Returns: 16
"00010111001110100000101101001100010011111111100110"
Returns: -1
"11101001011110011100110111100111000111000100001010"
Returns: -1
"01010101001001100110001101101110111100111111001100"
Returns: -1
"01000000100101011000001001011111111100100100100111"
Returns: -1
"10001110000011011101010011010001011111010100000001"
Returns: -1
"11110101100011101001011001110010110000"
Returns: -1
"0101011001101011010111000100010"
Returns: -1
"001001011000000011001011100001000111000"
Returns: -1
"11001111010110010000110011100110011111001101"
Returns: -1
"0011100"
Returns: -1
"1"
Returns: 1
"101"
Returns: 1
"11001"
Returns: 1
"1111101"
Returns: 1
"1001110001"
Returns: 1
"110000110101"
Returns: 1
"11110100001001"
Returns: 1
"10011000100101101"
Returns: 1
"1011111010111100001"
Returns: 1
"111011100110101100101"
Returns: 1
"100101010000001011111001"
Returns: 1
"10111010010000111011011101"
Returns: 1
"1110100011010100101001010001"
Returns: 1
"1001000110000100111001110010101"
Returns: 1
"101101011110011000100000111101001"
Returns: 1
"11100011010111111010100100110001101"
Returns: 1
"10001110000110111100100110111111000001"
Returns: 1
"1011000110100010101111000010111011000101"
Returns: 1
"110111100000101101101011001110100111011001"
Returns: 1
"100010101100011100100011000001001000100111101"
Returns: 1
"10101101011110001110101111000101101011000110001"
Returns: 1
"1101100011010111001001101011011100010111011110101"
Returns: 1
"11110011100111011100111100110110110111100110111001"
Returns: 16
"101110011100011001110001111110110011100011111101"
Returns: 7
"11001110011111010000100110110111100111110100001001"
Returns: 8
"1111010000100111110100001001110000110101"
Returns: 3
"101111011100110101100101110011011111010111100001"
Returns: 4
"111010001101010010100101000110011100011"
Returns: 3
"11110100001001111011100110101100101"
Returns: 2
"111101000010011001010100000010111110011"
Returns: 3
"1111101101110100100001110110111011100110011100011"
Returns: 5
"1001110001"
Returns: 1
"11011110000010110110101100111010011101100111001"
Returns: 2
"101110011100110110110110111001110011100110111001"
Returns: 12
"11111011100111001100111000110011100011011001110001"
Returns: 7
"1100110011100011111010000100110111110100001001"
Returns: 5
"111110110111110101111000011001110001"
Returns: 3
"101111011100110101100101100101010000001011111001"
Returns: 3
"100110001001011011110100011010100101001010001"
Returns: 2
"101101011110011000100000111101001101"
Returns: 2
"111011100110101100101101101"
Returns: 3
"1011111010111100001"
Returns: 1
"10111001110111100000101101101011001110100111011001"
Returns: 3
"10111010010000111011011101100101010000001011111001"
Returns: 2
"11111111111111111111111111110"
Returns: -1
"1011111011011111011011111011011111011011111011111"
Returns: 29
"0011"
Returns: -1
"00000000000000000000000001111111111111111111111111"
Returns: -1
"11001000110000100111001110010101"
Returns: 2
"10101101011110001110101111000101101011000110001101"
Returns: 2
"1000111000011011110010011011111100000110111001"
Returns: 3
"1010101"
Returns: -1
"111110111111011111101101"
Returns: 4
"1000000000000000000000000000000000000000000000000"
Returns: -1
"000001111101"
Returns: -1
"11010110101111000111010111100010110101100011000111"
Returns: 4
"110111110101"
Returns: -1
"11111011111010111100001"
Returns: 5
"11011000110101110010011010110111000101110111101011"
Returns: 2