QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100

#1289. A + B 问题

统计

二进制字符串是指仅由数字 “0” 和 “1” 组成的字符串。给定一个长度为 $(n + m)$ 的二进制字符串 $s$,请将其划分为两个子序列 $A = a_1a_2 \dots a_n$(长度为 $n$)和 $B = b_1b_2 \dots b_m$(长度为 $m$),使得 $s$ 中的每个数字恰好属于其中一个子序列。

令 $f$ 为将 “0” 和 “1” 序列转换为二进制整数的函数。例如,$f(\{1, 0, 1, 0\}) = 1010_2$ 且 $f(\{0, 0, 1, 0\}) = 10_2$。你的任务是找到这样的 $A$ 和 $B$,使得 $(f(A) + f(B))$ 最大化。

回想一下,字符串的子序列是指通过删除原字符串中若干字符(也可以不删除)而不改变剩余字符顺序所得到的序列。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$,表示测试数据的组数。对于每组测试数据:

第一行包含两个整数 $n$ 和 $m$ ($1 \le n, m \le 10^5$),表示所需子序列的长度。

第二行包含一个二进制字符串 $s$ ($|s| = n + m, s_i \in \{“0”, “1”\}$)。

保证所有测试数据的 $(n + m)$ 之和不超过 $2 \cdot 10^6$。

输出格式

对于每组测试数据,输出一行,包含一个二进制整数,表示 $(f(A) + f(B))$ 的最大可能结果。注意,$(f(A) + f(B))$ 应以二进制整数形式输出,且不含前导零;而 $A$ 和 $B$ 作为序列时,允许存在前导零。

样例

样例输入 1

3
4 3
1000101
2 2
1111
1 1
00

样例输出 1

1101
110
0

说明

我们现在使用下划线来标记二进制字符串中的子序列 $A$。

对于第一个样例测试数据,一种有效的划分方案是将字符串划分为 $\underline{1}000\underline{101}$,使得 $f(\{1, 1, 0, 1\}) + f(\{0, 0, 0\}) = 1101_2 + 0_2 = 1101_2$。

对于第二个样例测试数据,一种有效的划分方案是将字符串划分为 $\underline{11}11$,使得 $f(\{1, 1\}) + f(\{1, 1\}) = 11_2 + 11_2 = 110_2$。

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.