A10572 | Sleep in Class
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The academic year has just begun, but lessons and olympiads have already occupied all the free time. It is not a surprise that today Olga fell asleep on the Literature. She had a dream in which she was on a stairs.
The stairs consists of $n$ steps. The steps are numbered from bottom to top, it means that the lowest step has number $1$ , and the highest step has number $n$ . Above each of them there is a pointer with the direction (up or down) Olga should move from this step. As soon as Olga goes to the next step, the direction of the pointer (above the step she leaves) changes. It means that the direction "up" changes to "down", the direction "down" — to the direction "up".
Olga always moves to the next step in the direction which is shown on the pointer above the step.
If Olga moves beyond the stairs, she will fall and wake up. Moving beyond the stairs is a moving down from the first step or moving up from the last one (it means the $n$ -th) step.
In one second Olga moves one step up or down according to the direction of the pointer which is located above the step on which Olga had been at the beginning of the second.
For each step find the duration of the dream if Olga was at this step at the beginning of the dream.
Olga's fall also takes one second, so if she was on the first step and went down, she would wake up in the next second.
The stairs consists of $n$ steps. The steps are numbered from bottom to top, it means that the lowest step has number $1$ , and the highest step has number $n$ . Above each of them there is a pointer with the direction (up or down) Olga should move from this step. As soon as Olga goes to the next step, the direction of the pointer (above the step she leaves) changes. It means that the direction "up" changes to "down", the direction "down" — to the direction "up".
Olga always moves to the next step in the direction which is shown on the pointer above the step.
If Olga moves beyond the stairs, she will fall and wake up. Moving beyond the stairs is a moving down from the first step or moving up from the last one (it means the $n$ -th) step.
In one second Olga moves one step up or down according to the direction of the pointer which is located above the step on which Olga had been at the beginning of the second.
For each step find the duration of the dream if Olga was at this step at the beginning of the dream.
Olga's fall also takes one second, so if she was on the first step and went down, she would wake up in the next second.
输入格式
The first line contains single integer $n$ ( $1<=n<=10^{6}$ ) — the number of steps on the stairs.
The second line contains a string $s$ with the length $n$ — it denotes the initial direction of pointers on the stairs. The $i$ -th character of string $s$ denotes the direction of the pointer above $i$ -th step, and is either 'U' (it means that this pointer is directed up), or 'D' (it means this pointed is directed down).
The pointers are given in order from bottom to top.
The second line contains a string $s$ with the length $n$ — it denotes the initial direction of pointers on the stairs. The $i$ -th character of string $s$ denotes the direction of the pointer above $i$ -th step, and is either 'U' (it means that this pointer is directed up), or 'D' (it means this pointed is directed down).
The pointers are given in order from bottom to top.
输出格式
Print $n$ numbers, the $i$ -th of which is equal either to the duration of Olga's dream or to $-1$ if Olga never goes beyond the stairs, if in the beginning of sleep she was on the $i$ -th step.
输入输出样例
输入 #1
3 UUD
输出 #1
5 6 3
输入 #2
10 UUDUDUUDDU
输出 #2
5 12 23 34 36 27 18 11 6 1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted