Rings solution codeforces
Somewhere in a parallel Middle-earth, when Saruman caught Frodo, he only found 0 if the -th ring was gold, and 1 if it was silver.rings. And the -th ring was either gold or silver. For convenience Saruman wrote down a binary string of characters, where the -th character was
Saruman has a magic function, which takes a binary string and returns a number obtained by converting the string into a binary number and then converting the binary number into a decimal number. For example, .
Saruman, however, thinks that the order of the rings plays some important role. He wants to findpairs of integers , such that:
- , ,
- , ,
- Pairs and are distinct. That is, at least one of and must hold.
- Let there exists non-negative integer , such that . be the substring of , and be the substring of . Then
Here substringdenotes , and denotes rounding the number down to the nearest integer.
Help Saruman solve this problem! It is guaranteed that under the constraints of the problem at least one solution exists.
Each test contains multiple test cases.
The first line contains one positive integer( ), denoting the number of test cases. Description of the test cases follows.
The first line of each test case contains one positive integer( ) — length of the string.
The second line of each test case contains a non-empty binary string of length.
It is guaranteed that the sum ofover all test cases does not exceed .
For every test case print four integers, , , , which denote the beginning of the first substring, the end of the first substring, the beginning of the second substring, and the end of the second substring, respectively.
If there are multiple solutions, print any.
7 6 101111 9 111000111 8 10000000 5 11011 6 001111 3 101 30 100000000000000100000000000000
3 6 1 3 1 9 4 9 5 8 1 4 1 5 3 5 1 6 2 4 1 2 2 3 1 15 16 30
In the first testcase, .
In the second testcase, .
In the third testcase, .
In the fourth testcase, .
In the fifth testcase, .
Solution: Click here