2065E.md (2883B)
1 Source: https://codeforces.com/problemset/problem/2065/E 2 3 E. Skibidus and Rizz 4 5 time limit per test 6 7 1.5 seconds 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 With the approach of Valentine's Day, Skibidus desperately needs a way to rizz up his crush! Fortunately, he knows of just the way: creating the perfect Binary String! 22 23 Given a binary string$^{\text{∗}}$ $t$, let $x$ represent the number of $\texttt{0}$ in $t$ and $y$ represent the number of $\texttt{1}$ in $t$. Its balance-value is defined as the value of $\max(x-y, y-x)$. 24 25 Skibidus gives you three integers $n$, $m$, and $k$. He asks for your help to construct a binary string $s$ of length $n+m$ with exactly $n$ $\texttt{0}$'s and $m$ $\texttt{1}$'s such that the maximum balance-value among all of its substrings$^{\text{†}}$ is exactly $k$. If it is not possible, output -1. 26 27 $^{\text{∗}}$A binary string only consists of characters $\texttt{0}$ and $\texttt{1}$. 28 29 $^{\text{†}}$A string $a$ is a substring of a string $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end. 30 31 Input 32 33 The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. 34 35 The first and only line of each test case contains three integers $n$, $m$, and $k$ ($0 \leq n, m \leq 2\cdot 10^5$, $1 \leq k \leq n + m$, $n+m\geq 1$). 36 37 It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases does not exceed $2\cdot 10^5$. 38 39 Output 40 41 For each test case, if it is possible to construct $s$, output it on a new line. If there are multiple possible $s$, output any. Otherwise, output -1 on a new line. 42 43 Example 44 45 Input 46 47 ``` 48 6 49 50 1 2 1 51 52 4 3 2 53 54 2 4 3 55 56 8 3 2 57 58 5 0 4 59 60 5 0 5 61 ``` 62 63 Output 64 65 ``` 66 101 67 0100101 68 011011 69 -1 70 -1 71 00000 72 ``` 73 74 Note 75 76 In the first test case, we must construct $s$ such that it contains one $\texttt{0}$, two $\texttt{1}$, and a maximum balance of $1$ among all of its substrings. One possible valid $s$ is $\texttt{101}$ because: 77 78 * Consider the substring bounded by indices $[1, 1]$. Its balance-value is $\max(0 - 1, 1 - 0) = 1$. 79 * Consider the substring bounded by indices $[1, 2]$. Its balance-value is $\max(1 - 1, 1 - 1) = 0$. 80 * Consider the substring bounded by indices $[1, 3]$. Its balance-value is $\max(1 - 2, 2 - 1) = 1$. 81 * Consider the substring bounded by indices $[2, 2]$. Its balance-value is $\max(1 - 0, 0 - 1) = 1$. 82 * Consider the substring bounded by indices $[2, 3]$. Its balance-value is $\max(1 - 1, 1 - 1) = 0$. 83 * Consider the substring bounded by indices $[3, 3]$. Its balance-value is $\max(0 - 1, 1 - 0) = 1$. 84 85 Among all possible substrings, the maximum balance-value is $1$. 86 87 In the second test case, the substring with the maximum balance-value is $0100$, which has a balance of $max(3-1, 1-3)=2$.