CF954A.Diagonal Walking

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.

In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.

Your problem is to print the minimum possible length of the sequence of moves after the replacements.

米哈伊尔在二维平面上行走,每次只能向上或向右移动。给你一个描述米哈伊尔移动的序列。他认为该序列过长,希望将其尽可能缩短。

在给定序列中,“向上”移动用字符 U 表示,“向右”移动用字符 R 表示。米哈伊尔可以将任意一对连续的移动 RU 或 UR 替换为一次对角线移动(用字符 D 表示)。之后他可继续进行其他替换,直到序列中不再存在连续的 RU 或 UR 为止。

你的任务是输出经过所有可能替换后,移动序列的最小可能长度。

输入格式

The first line of the input contains one integer n (1 ≤ n ≤ 100) — the length of the sequence. The second line contains the sequence consisting of n characters U and R.

输入的第一行包含一个整数 nn(1 ≤ n ≤ 1001 \leq n \leq 100)——序列的长度。第二行包含由 nn 个字符 U 和 R 组成的序列。

输出格式

Print the minimum possible length of the sequence of moves after all replacements are done.

输出完成所有替换后移动序列的最小可能长度。

输入输出样例

  • 输入#1

    5
    RUURU

    输出#1

    3
  • 输入#2

    17
    UUURRRRRUUURURUUU

    输出#2

    13

说明/提示

In the first test the shortened sequence of moves may be DUD (its length is 3).

In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).

在第一个测试中,缩短后的移动序列可以是 DUD(其长度为 3)。

在第二个测试中,缩短后的移动序列可以是 UUDRRRDUDDUUU(其长度为 13)。

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

首页