CF2250B.String Construction

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two integers nn and kk.

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

  • The absolute difference between the number of characters 0\mathtt{0} and the number of characters 1\mathtt{1} in ss is at most 11.
  • There are exactly kk pairs of adjacent equal characters in ss. Formally, there are exactly kk indices ii (1≤i≤n−11 \le i \le n-1) satisfying si=si+1s_i = s_{i + 1}.

Or determine that no such string exists.

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

给你两个整数 nn 和 kk。

构造一个长度为 nn 的二进制字符串∗^{\text{∗}} ss,使得以下两个条件均成立:

  • 字符串 ss 中字符 0\mathtt{0} 的个数与字符 1\mathtt{1} 的个数之差的绝对值至多为 11。
  • ss 中恰好有 kk 对相邻且相等的字符。形式化地说,恰好存在 kk 个下标 ii(1≤i≤n−11 \le i \le n-1),满足 si=si+1s_i = s_{i + 1}。

或者判断不存在满足条件的字符串。

∗^{\text{∗}}二进制字符串是指每个字符均为 0\mathtt{0} 或 1\mathtt{1} 的字符串。

输入格式

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

The only line of each test case contains two integers nn and kk (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5, 0≤k≤n−10 \le k \le n-1).

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10001 \le t \le 1000)。随后是各测试用例的描述。

每个测试用例仅有一行,包含两个整数 nn 和 kk(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5,0≤k≤n−10 \le k \le n-1)。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

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

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

对于每个测试用例,输出一个长度为 nn 的二进制字符串 ss —— 即你构造出的字符串。如果不存在这样的字符串,则输出 −1-1。

如果有多个答案,你可以输出其中任意一个。

输入输出样例

  • 输入#1

    8
    5 2
    4 3
    6 1
    5 0
    7 3
    4 2
    3 2
    7 4

    输出#1

    01110
    -1
    101001
    01010
    0100011
    0011
    -1
    0111000

说明/提示

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

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

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

在第一个测试用例中,一个可能的答案是 s=01110s=\mathtt{01110}。它包含三个字符 1\mathtt{1} 和两个字符 0\mathtt{0},且 ss 中恰好有 22 对相邻相等的字符:(s2,s3)(s_2, s_3) 和 (s3,s4)(s_3, s_4)。

在第二个测试用例中,k=n−1k=n-1。ss 中所有字符必须相同,因此字符 0\mathtt{0} 和 1\mathtt{1} 的数量不可能至多相差 11。故答案为 −1-1。

在第三个测试用例中,请注意 010110\mathtt{010110} 也是一个可能的答案。

输入解题思路,AI测评打分。不知道怎么写?

首页