CF578E.Walking!

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is a sand trail in front of Alice's home.

In daytime, people walk over it and leave a footprint on the trail for their every single step. Alice cannot distinguish the order of the footprints, but she can tell whether each footprint is made by left foot or right foot. Also she's certain that all people are walking by alternating left foot and right foot.

For example, suppose that one person walked through the trail and left some footprints. The footprints are RRLRL in order along the trail ('R' means right foot and 'L' means left foot). You might think the outcome of the footprints is strange. But in fact, some steps are resulting from walking backwards!

There are some possible order of steps that produce these footprints such as 1 → 3 → 2 → 5 → 4 or 2 → 3 → 4 → 5 → 1 (we suppose that the distance between two consecutive steps can be arbitrarily long). The number of backward steps from above two examples are 2 and 1 separately.

Alice is interested in these footprints. Whenever there is a person walking trough the trail, she takes a picture of all these footprints along the trail and erase all of them so that next person will leave a new set of footprints. We know that people walk by alternating right foot and left foot, but we don't know if the first step is made by left foot or right foot.

Alice wants to know the minimum possible number of backward steps made by a person. But it's a little hard. Please help Alice to calculate it. You also need to construct one possible history of these footprints.

爱丽丝家门前有一条沙土小径。

白天,人们走过小径时,每走一步都会在小径上留下一个脚印。爱丽丝无法分辨脚印出现的先后顺序,但她能判断每个脚印是由左脚(L)还是右脚(R)留下的。此外,她确信所有人行走时都是左右脚交替迈步的。

例如,假设有一个人走过小径并留下了一些脚印,这些脚印沿小径顺序排列为 RRLRL(其中 'R' 表示右脚脚印,'L' 表示左脚脚印)。你可能会觉得这个脚印序列看起来很奇怪。但事实上,其中一些步子是倒着走产生的!

存在若干种可能的落脚顺序可生成这些脚印,例如:
1→3→2→5→41 \rightarrow 3 \rightarrow 2 \rightarrow 5 \rightarrow 4 或 2→3→4→5→12 \rightarrow 3 \rightarrow 4 \rightarrow 5 \rightarrow 1
(我们假设相邻两步之间的距离可以任意长)。上述两个例子中,倒走的步数分别为 22 和 11。

爱丽丝对这些脚印很感兴趣。每当有人走过小径,她就会拍下小径上所有脚印的照片,并将它们全部擦除,以便下一个人留下全新的一组脚印。我们知道人们行走时左右脚严格交替,但我们并不知道第一步是左脚还是右脚。

爱丽丝想知道:产生给定脚印序列的某个人,其最少可能的倒走步数是多少?这个问题稍有难度,请你帮助爱丽丝计算该最小值,并同时构造出一种可行的落脚顺序(即脚印产生历史)。

输入格式

Only one line containing the string S (1 ≤ |S| ≤ 100 000) containing all footprints in order along the trail from entrance to exit.

It is guaranteed that there is at least one possible footprint history.

仅一行,包含字符串 SS(1 ≤ ∣S∣ ≤ 100 0001 ≤ |S| ≤ 100\,000),表示从入口到出口沿小径依次出现的所有足迹。

保证至少存在一种可能的足迹历史。

输出格式

You should output 2 lines.

The first line should contain a number denoting the minimum number of backward steps.

The second line should contain a permutation of integers from 1 to |S|. This permutation should denote the order of footprints that may possible be used by person walked there.

If there are several possible answers, you may output any of them.

你应该输出 2 行。

第一行应包含一个数字,表示最少的向后步数。

第二行应包含一个从 11 到 ∣S∣|S| 的整数排列。该排列表示此人行走时可能留下的足迹顺序。

如果存在多个可能的答案,你可以输出其中任意一个。

输入输出样例

  • 输入#1

    RRLRL

    输出#1

    1
    2 5 1 3 4
  • 输入#2

    RLRLRLRLR

    输出#2

    0
    1 2 3 4 5 6 7 8 9
  • 输入#3

    RRRRRLLLL

    输出#3

    4
    4 9 3 8 2 7 1 6 5

说明/提示

For the first sample, one possible order is 2 → 5 → 1 → 3 → 4, among them only the step 5 → 1 is backward step so the answer is 1.

For the second example one possible order is just to follow the order of input, thus there are no backward steps.

For the third sample, there will be 4 backward steps because every step from L to R will be a backward step.

对于第一个样例,一种可能的顺序是 2→5→1→3→42\to5\to1\to3\to4,其中仅有步骤 5→15\to1 是后退步,因此答案为 11。

对于第二个样例,一种可能的顺序即按输入顺序排列,因此不存在后退步。

对于第三个样例,将存在 44 个后退步,因为从 LL 到 RR 的每一步均为后退步。

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

首页