Codeforces Round 1112 (Div. 2)
B
字符串构造
String Construction
Codeforces
1000
原题
← AC →

字符串构造AI (CI翻译)

You are given two integers $n$ and $k$.

给定两个整数 $n$ 和 $k$。AI (CI翻译)

Construct a binary string$^{\text{∗}}$ $s$ of length $n$, such that both of the following conditions hold:

构造一个长度为 $n$ 的二进制字符串$^{\text{∗}}$ $s$,使其满足以下两个条件:AI (CI翻译)

  • The absolute difference between the number of characters $\mathtt{0}$ and the number of characters $\mathtt{1}$ in $s$ is at most $1$.
  • There are exactly $k$ pairs of adjacent equal characters in $s$. Formally, there are exactly $k$ indices $i$ ($1 \le i \le n-1$) satisfying $s_i = s_{i + 1}$.
  • $s$ 中字符 $\mathtt{0}$ 的数量与字符 $\mathtt{1}$ 的数量之差的绝对值至多为 $1$。
  • $s$ 中恰好有 $k$ 对相邻且相同的字符。形式化地说,恰好有 $k$ 个下标 $i$($1 \le i \le n-1$)满足 $s_i = s_{i + 1}$。
AI (CI翻译)

Or determine that no such string exists.

或者,判断不存在满足条件的字符串。AI (CI翻译)

$^{\text{∗}}$A binary string is a string where each character is either $\mathtt{0}$ or $\mathtt{1}$.

$^{\text{∗}}$二进制字符串是指每个字符均为 $\mathtt{0}$ 或 $\mathtt{1}$ 的字符串。AI (CI翻译)

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.

每个测试包含多组测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 1000$)。接下来是各测试用例的描述。AI (CI翻译)

The only line of each test case contains two integers $n$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $0 \le k \le n-1$).

每个测试用例仅一行,包含两个整数 $n$ 和 $k$($2 \le n \le 2 \cdot 10^5$,$0 \le k \le n-1$)。AI (CI翻译)

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

保证所有测试用例中 $n$ 的总和不超过 $2 \cdot 10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, output a binary string $s$ of length $n$ — the string you constructed. Print $-1$ if such a string does not exist.

对于每个测试用例,输出一个长度为 $n$ 的二进制字符串 $s$,即你构造出的字符串。如果不存在满足条件的字符串,则输出 $-1$。AI (CI翻译)

If there are multiple answers, you may output any of them.

如果有多个答案,输出其中任意一个即可。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, one possible answer is $s=\mathtt{01110}$. It contains three characters $\mathtt{1}$ and two characters $\mathtt{0}$, and there are exactly $2$ adjacent equal pairs in $s$: $(s_2, s_3)$ and $(s_3, s_4)$.

在第一个测试用例中,一种可能的答案是 $s=\mathtt{01110}$。其中包含三个字符 $\mathtt{1}$ 和两个字符 $\mathtt{0}$,并且 $s$ 中恰好有 $2$ 对相邻且相同的字符:$(s_2, s_3)$ 和 $(s_3, s_4)$。AI (CI翻译)

In the second test case, $k=n-1$. All characters in $s$ should be equal, so the numbers of characters $\mathtt{0}$ and $\mathtt{1}$ could not differ by at most $1$. Thus, the answer is $-1$.

在第二个测试用例中,$k=n-1$。此时 $s$ 中的所有字符都应相同,因此字符 $\mathtt{0}$ 和字符 $\mathtt{1}$ 的数量之差不可能至多为 $1$。所以答案为 $-1$。AI (CI翻译)

In the third test case, note that $\mathtt{010110}$ is also a possible answer.

在第三个测试用例中,注意到 $\mathtt{010110}$ 也是一个可能的答案。AI (CI翻译)

样例

Input #1
8
5 2
4 3
6 1
5 0
7 3
4 2
3 2
7 4
Output #1
01110
-1
101001
01010
0100011
0011
-1
0111000
InputCopy OutputCopy
题目信息
题号
2250B
时间限制
1 s
内存限制
256 MB
标签
构造

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。