CF748C.Santa Claus and Robot

普及/提高-

通过率:0%

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 mm points p1,p2,...,pmp_{1},p_{2},...,p_{m} with integer coordinates, do the following: denote its initial location by p0p_{0} . First, the robot will move from p0p_{0} to p1p_{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 p1p_{1} , it'll move to p2p_{2} , again, choosing one of the shortest ways, then to p3p_{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.

输入格式

The first line of input contains the only positive integer nn ( 1<=n<=21051<=n<=2·10^{5} ) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of nn letters, each being equal either L, or R, or U, or D. kk -th letter stands for the direction which Robot traveled the kk -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.

输出格式

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.

首页