1562C.md (3238B)
1 Source: https://codeforces.com/problemset/problem/1562/C 2 3 C. Rings 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Frodo was caught by Saruman. He tore a pouch from Frodo's neck, shook out its contents —there was a pile of different rings: gold and silver... 22 23 "How am I to tell which is the One?!" the mage howled. 24 25 "Throw them one by one into the Cracks of Doom and watch when Mordor falls!" 26 27 Somewhere in a parallel Middle-earth, when Saruman caught Frodo, he only found $n$ rings. And the $i$-th ring was either gold or silver. For convenience Saruman wrote down a binary string $s$ of $n$ characters, where the $i$-th character was 0 if the $i$-th ring was gold, and 1 if it was silver. 28 29 Saruman has a magic function $f$, 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, $f(001010) = 10, f(111) = 7, f(11011101) = 221$. 30 31 Saruman, however, thinks that the order of the rings plays some important role. He wants to find $2$ pairs of integers $(l_1, r_1), (l_2, r_2)$, such that: 32 33 * $1 \le l_1 \le n$, $1 \le r_1 \le n$, $r_1-l_1+1\ge \lfloor \frac{n}{2} \rfloor$ 34 * $1 \le l_2 \le n$, $1 \le r_2 \le n$, $r_2-l_2+1\ge \lfloor \frac{n}{2} \rfloor$ 35 * Pairs $(l_1, r_1)$ and $(l_2, r_2)$ are distinct. That is, at least one of $l_1 \neq l_2$ and $r_1 \neq r_2$ must hold. 36 * Let $t$ be the substring $s[l_1:r_1]$ of $s$, and $w$ be the substring $s[l_2:r_2]$ of $s$. Then there exists non-negative integer $k$, such that $f(t) = f(w) \cdot k$. 37 38 Here substring $s[l:r]$ denotes $s_ls_{l+1}\ldots s_{r-1}s_r$, and $\lfloor x \rfloor$ denotes rounding the number down to the nearest integer. 39 40 Help Saruman solve this problem! It is guaranteed that under the constraints of the problem at least one solution exists. 41 42 Input 43 44 Each test contains multiple test cases. 45 46 The first line contains one positive integer $t$ ($1 \le t \le 10^3$), denoting the number of test cases. Description of the test cases follows. 47 48 The first line of each test case contains one positive integer $n$ ($2 \le n \le 2 \cdot 10^4$) — length of the string. 49 50 The second line of each test case contains a non-empty binary string of length $n$. 51 52 It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. 53 54 Output 55 56 For every test case print four integers $l_1$, $r_1$, $l_2$, $r_2$, 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. 57 58 If there are multiple solutions, print any. 59 60 Example 61 62 Input 63 64 ``` 65 7 66 6 67 101111 68 9 69 111000111 70 8 71 10000000 72 5 73 11011 74 6 75 001111 76 3 77 101 78 30 79 100000000000000100000000000000 80 ``` 81 82 Output 83 84 ``` 85 3 6 1 3 86 1 9 4 9 87 5 8 1 4 88 1 5 3 5 89 1 6 2 4 90 1 2 2 3 91 1 15 16 30 92 ``` 93 94 Note 95 96 In the first testcase $f(t) = f(1111) = 15$, $f(w) = f(101) = 5$. 97 98 In the second testcase $f(t) = f(111000111) = 455$, $f(w) = f(000111) = 7$. 99 100 In the third testcase $f(t) = f(0000) = 0$, $f(w) = f(1000) = 8$. 101 102 In the fourth testcase $f(t) = f(11011) = 27$, $f(w) = f(011) = 3$. 103 104 In the fifth testcase $f(t) = f(001111) = 15$, $f(w) = f(011) = 3$.