CF1012D.AB-Strings

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are two strings s and t, consisting only of letters a and b. You can make the following operation several times: choose a prefix of s, a prefix of t and swap them. Prefixes can be empty, also a prefix can coincide with a whole string.

Your task is to find a sequence of operations after which one of the strings consists only of a letters and the other consists only of b letters. The number of operations should be minimized.

有两个仅由字母 a 和 b 组成的字符串 s 和 t。你可以执行以下操作若干次:选择 s 的一个前缀和 t 的一个前缀,并交换它们。前缀可以为空,也可以与整个字符串重合。

你的任务是找出一个操作序列,使得操作结束后,其中一个字符串仅由字母 a 组成,另一个字符串仅由字母 b 组成。要求操作次数尽可能少。

输入格式

The first line contains a string s (1 ≤ |s| ≤ 2·105).

The second line contains a string t (1 ≤ |t| ≤ 2·105).

Here |s| and |t| denote the lengths of s and t, respectively. It is guaranteed that at least one of the strings contains at least one a letter and at least one of the strings contains at least one b letter.

第一行包含一个字符串 ss(1 ≤ ∣s∣ ≤ 2⋅1051 \leq |s| \leq 2\cdot10^5)。

第二行包含一个字符串 tt(1 ≤ ∣t∣ ≤ 2⋅1051 \leq |t| \leq 2\cdot10^5)。

其中 ∣s∣|s| 和 ∣t∣|t| 分别表示字符串 ss 和 tt 的长度。保证至少有一个字符串中包含至少一个字母 a,且至少有一个字符串中包含至少一个字母 b。

输出格式

The first line should contain a single integer n (0 ≤ n ≤ 5·105) — the number of operations.

Each of the next n lines should contain two space-separated integers a__i, b__i — the lengths of prefixes of s and t to swap, respectively.

If there are multiple possible solutions, you can print any of them. It's guaranteed that a solution with given constraints exists.

第一行应包含一个整数 nn(0 ≤ n ≤ 5⋅1050 \leq n \leq 5\cdot10^5)—— 表示操作的次数。

接下来的 nn 行中,每行应包含两个用空格分隔的整数 aia_i、bib_i —— 分别表示字符串 ss 和 tt 的待交换前缀的长度。

如果存在多种可能的解,你可以输出其中任意一个。在给定约束条件下,保证至少存在一个解。

输入输出样例

  • 输入#1

    bab
    bb

    输出#1

    2
    1 0
    1 3
  • 输入#2

    bbbb
    aaa

    输出#2

    0

说明/提示

In the first example, you can solve the problem in two operations:

  1. Swap the prefix of the first string with length 1 and the prefix of the second string with length 0. After this swap, you'll have strings ab and bbb.
  2. Swap the prefix of the first string with length 1 and the prefix of the second string with length 3. After this swap, you'll have strings bbbb and a.

In the second example, the strings are already appropriate, so no operations are needed.

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

  1. 交换第一个字符串长度为 11 的前缀与第二个字符串长度为 00 的前缀。此次交换后,您将得到字符串 ab 和 bbb。
  2. 交换第一个字符串长度为 11 的前缀与第二个字符串长度为 33 的前缀。此次交换后,您将得到字符串 bbbb 和 a。

在第二个例子中,字符串已满足要求,因此无需任何操作。

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

首页