QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#325. AB-Strings

Statistics

有两个字符串 $s$ 和 $t$,仅由字母 ab 组成。你可以多次执行以下操作:选择 $s$ 的一个前缀和 $t$ 的一个前缀,并将它们交换。前缀可以为空,也可以是整个字符串。

你的任务是找到一个操作序列,使得操作后其中一个字符串仅由 a 组成,另一个字符串仅由 b 组成。操作次数应尽可能少,但找到非最优序列的解法也能获得部分分数。请阅读评分部分以获取更详细的信息。

输入格式

第一行包含一个字符串 $s$ ($1 \le |s| \le 2 \cdot 10^5$)。

第二行包含一个字符串 $t$ ($1 \le |t| \le 2 \cdot 10^5$)。

这里 $|s|$ 和 $|t|$ 分别表示 $s$ 和 $t$ 的长度。保证至少有一个字符串中至少包含一个 a,且至少有一个字符串中至少包含一个 b

输出格式

第一行应包含一个整数 $n$ ($0 \le n \le 5 \cdot 10^5$),表示操作次数。

接下来的 $n$ 行,每行包含两个空格分隔的整数 $a_i, b_i$,分别表示要交换的 $s$ 和 $t$ 的前缀长度。

如果存在多种可能的解,你可以输出其中任意一种。

子任务

设 $n$ 为你给出的序列长度,$m$ 为某个最优序列的长度。

  • 如果对于该组的所有测试数据均满足 $n = m$,你将获得该组 100% 的分数。
  • 如果对于该组的所有测试数据均满足 $n \le m + 2$,你将获得该组 70% 的分数(向下取整)。
  • 如果对于该组的所有测试数据均满足 $n \le 2m + 2$,你将获得该组 50% 的分数(向下取整)。
  • 如果对于该组的所有测试数据均满足 $n \le 5 \cdot 10^5$,你将获得该组 30% 的分数(向下取整)。
  • 如果对于至少一个测试数据你输出的 $n > 5 \cdot 10^5$,你将获得 WA,且该组得分为 0。
子任务 分数 数据范围 说明
0 0 样例测试
1 5 $1 \le s , t \le 6$ $s$ 和 $t$ 合计恰好包含一个字母 a
2 10 $1 \le s , t \le 6$
3 20 $1 \le s , t \le 50$
4 20 $1 \le s , t \le 250$
5 20 $1 \le s , t \le 2000$
6 25 $1 \le s , t \le 2 \cdot 10^5$

样例

样例 1

输入

bab
bb

输出

2
1 0
1 3

样例 2

输入

bbbb
aaa

输出

0

说明

在第一个样例中,你可以通过两次操作解决问题:

  1. 交换第一个字符串长度为 1 的前缀和第二个字符串长度为 0 的前缀。交换后,你将得到字符串 abbbb
  2. 交换第一个字符串长度为 1 的前缀和第二个字符串长度为 3 的前缀。交换后,你将得到字符串 bbbba

在第二个样例中,字符串已经符合要求,因此不需要进行任何操作。

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.