CF733E.Sleep in Class

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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.

新学年刚刚开始,但课程和奥赛已经占满了所有空闲时间。因此,今天奥尔加在文学课上睡着了。她做了一个梦,梦见自己站在一段楼梯上。

这段楼梯共有 nn 级台阶,台阶从下到上编号,即最底层的台阶编号为 11,最顶层的台阶编号为 nn。每级台阶上方都有一个指针,指示奥尔加从此台阶出发时应移动的方向(向上或向下)。每当奥尔加走向下一级台阶后,她离开的那级台阶上方的指针方向就会翻转:即“向上”变为“向下”,“向下”变为“向上”。

奥尔加总是按照当前所处台阶上方指针所指示的方向,移动到相邻的下一级台阶。

若奥尔加移出楼梯范围,她便会坠落并惊醒。“移出楼梯范围”定义为:从第 11 级台阶向下移动,或从第 nn 级(即最顶层)台阶向上移动。

每秒钟,奥尔加根据她在该秒开始时刻所处台阶上方指针指示的方向,向上或向下移动一级台阶。

对每一级台阶,请计算:若奥尔加在梦境开始时刻恰好位于该台阶,则整个梦境持续多长时间(单位:秒)?

奥尔加坠落本身也耗时一秒。例如,若她起始时位于第 11 级台阶且向下移动,则将在下一秒醒来。

输入格式

The first line contains single integer n (1 ≤ n ≤ 106) — 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.

第一行包含一个整数 nn(1≤n≤1061 \leq n \leq 10^6)—— 表示楼梯的阶数。

第二行包含一个长度为 nn 的字符串 ss —— 表示楼梯上各指针的初始指向。字符串 ss 的第 ii 个字符表示第 ii 阶楼梯上方指针的指向,该字符为 'U'(表示该指针指向上方)或 'D'(表示该指针指向下方)。

指针按从下到上的顺序给出。

输出格式

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.

输出 n 个数,其中第 i 个数等于奥尔加梦境的持续时间;若奥尔加在入睡初始时刻位于第 i 级台阶时,从未踏出楼梯范围,则该数为  - 1。

输入输出样例

  • 输入#1

    3
    UUD

    输出#1

    5 6 3
  • 输入#2

    10
    UUDUDUUDDU

    输出#2

    5 12 23 34 36 27 18 11 6 1

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

首页