QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 512 MB 満点: 100

#6351. 精确子序列

統計

考虑所有恰好有 $n$ 个不同非空子序列(按内容区分)的二进制字符串。将这些字符串按字典序排序,找出该顺序下的第 $k$ 个字符串。

输入格式

每个测试包含多个测试用例。第一行包含一个整数 $t$ ($1 \le t \le 100$),表示测试用例的数量。接下来是 $t$ 个测试用例的描述。 每个测试用例的描述由一行包含两个整数 $n$ 和 $k$ ($1 \le n, k \le 10^9$) 组成。

输出格式

对于每个测试用例,如果恰好有 $n$ 个不同非空子序列的二进制字符串少于 $k$ 个,则输出 -1。否则,在接下来的两行中按以下格式输出字典序第 $k$ 小的字符串:

非空二进制字符串可以通过其第一个字符和连续相同字符块的长度列表唯一确定。第一行输出 $m$ 和 $c$,其中 $m$ 是块的数量,$c$ 是第一个字符。第二行按顺序输出块的长度 $L_1, L_2, \dots, L_m$。

样例

输入 1

8
3 1
3 2
3 3
3 4
3 5
1000000000 1
99824 4353
2129721 207087

输出 1

1 0
3
2 0
1 1
2 1
1 1
1 1
3
-1
1 0
1000000000
11 0
9 2 2 1 6 2 1 2 7 1 1
9 0
9 9 8 2 4 4 3 5 3

说明

样例对应的实际字符串为: 000 01 10 111 -1 000...000 (1000000000 次) 0000000001100100000011011000000010 00000000011111111100000000110000111100011111000

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.