QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 512 MB 總分: 100

#2626. Kilk Not

统计

给定一个由字符 '0'、'1' 和 '?' 组成的字符串 $s$。其中 '?' 的总数为 $a + b$。

你需要将 $a$ 个 '?' 替换为 '0',将 $b$ 个 '?' 替换为 '1',从而得到一个二进制字符串 $t$。令 $f(t)$ 为 $t$ 中由相同数字组成的最长子串的长度(例如 11111 或 0000)。

你的任务是最小化 $f(t)$。

输入格式

每个测试包含多个测试用例。第一行包含测试用例的数量 $t$ ($1 \le t \le 10^5$)。

接下来是各测试用例的描述。

每个测试用例的第一行包含三个整数 $n$、$a$ 和 $b$ ($1 \le n \le 250\,000$; $0 \le a$; $0 \le b$)。

第二行包含一个长度为 $n$ 的字符串 $s$,由字符 '0'、'1' 和 '?' 组成。$s$ 中 '?' 的数量等于 $a + b$。

保证所有测试用例的 $n$ 之和不超过 $250\,000$。

输出格式

对于每个测试用例,输出两行。

第一行输出一个整数 $f(t)$,表示由相同数字组成的最长子串的最小可能长度。

第二行输出任意一个达到该 $f(t)$ 值的字符串 $t$。

样例

输入 1

4
7 1 2
0?01??0
10 5 0
?000??0?0?
11 0 0
11001110100
15 2 4
?1?11?1??11100?

输出 1

1
0101010
10
0000000000
3
11001110100
4
110111101111001

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1570Editorial Open集训队作业 解题报告 by 周裕杭Anonymous2026-04-17 20:19:06 Download

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.