A10014 | Walking!
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
Only one line containing the string $S$ ( $1<=|S|<=100000$ ) containing all footprints in order along the trail from entrance to exit.
It is guaranteed that there is at least one possible footprint history.
It is guaranteed that there is at least one possible footprint history.
输出格式
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.
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.
输入输出样例
输入 #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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted