CF748C.Santa Claus and Robot

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of m points _p_1, _p_2, ..., p__m with integer coordinates, do the following: denote its initial location by _p_0. First, the robot will move from _p_0 to _p_1 along one of the shortest paths between them (please notice that since the robot moves only along the grid lines, there can be several shortest paths). Then, after it reaches _p_1, it'll move to _p_2, again, choosing one of the shortest ways, then to _p_3, and so on, until he has visited all points in the given order. Some of the points in the sequence may coincide, in that case Robot will visit that point several times according to the sequence order.

While Santa was away, someone gave a sequence of points to Robot. This sequence is now lost, but Robot saved the protocol of its unit movements. Please, find the minimum possible length of the sequence.

圣诞老人有一个机器人,该机器人生活在无限网格上,并能沿网格线移动。给定一个由 mm 个具有整数坐标的点 p1, p2, …, pmp_1,\,p_2,\,\dots,\,p_m 构成的序列,机器人可执行如下操作:设其初始位置为 p0p_0。首先,机器人将从 p0p_0 沿 p0p_0 与 p1p_1 之间的某条最短路径移动至 p1p_1(请注意:由于机器人仅能沿网格线移动,因此 p0p_0 与 p1p_1 之间可能存在多条最短路径)。接着,在抵达 p1p_1 后,它将再次选择一条最短路径前往 p2p_2,然后前往 p3p_3,依此类推,直至按给定顺序访问完所有点。序列中某些点可能重合;此时,机器人将严格按照序列顺序多次访问该点。

圣诞老人外出期间,有人向机器人提供了一个点序列。该序列现已丢失,但机器人保存了其每次单位长度移动的完整日志。请找出该点序列可能的最小长度。

输入格式

The first line of input contains the only positive integer n (1 ≤ n ≤ 2·105) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of n letters, each being equal either L, or R, or U, or D. k-th letter stands for the direction which Robot traveled the k-th unit segment in: L means that it moved to the left, R — to the right, U — to the top and D — to the bottom. Have a look at the illustrations for better explanation.

输入的第一行包含唯一的一个正整数 nn(1 ≤ n ≤ 2⋅1051 \leq n \leq 2\cdot10^5),表示机器人所走过的单位线段数量。第二行包含移动协议,由 nn 个字母组成,每个字母为 L、R、U 或 D 中的一个。第 kk 个字母表示机器人在第 kk 段单位线段中所移动的方向:L 表示向左,R 表示向右,U 表示向上,D 表示向下。可参考图示以获得更清晰的解释。

输出格式

The only line of input should contain the minimum possible length of the sequence.

输入的唯一一行应包含序列的最小可能长度。

输入输出样例

  • 输入#1

    4
    RURD

    输出#1

    2
  • 输入#2

    6
    RRULDD

    输出#2

    2
  • 输入#3

    26
    RRRULURURUULULLLDLDDRDRDLD

    输出#3

    7
  • 输入#4

    3
    RLL

    输出#4

    2
  • 输入#5

    4
    LRLR

    输出#5

    4

说明/提示

The illustrations to the first three tests are given below.

The last example illustrates that each point in the sequence should be counted as many times as it is presented in the sequence.

前三个测试用例的示意图如下所示。

最后一个示例说明:序列中的每个点应被计数与其在序列中出现的次数相同。

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

首页