CF888B.Buggy Robot
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0, 0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (x, y) to (x, y + 1);
- D — move from (x, y) to (x, y - 1);
- L — move from (x, y) to (x - 1, y);
- R — move from (x, y) to (x + 1, y).
Ivan entered a sequence of n commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0, 0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations!
伊万有一个位于无限网格上的机器人。初始时,机器人位于起始格子 (0,0)。机器人可以执行命令,共有四种类型的命令:
U— 从格子 (x,y) 移动到 (x,y+1);D— 从格子 (x,y) 移动到 (x,y−1);L— 从格子 (x,y) 移动到 (x−1,y);R— 从格子 (x,y) 移动到 (x+1,y)。
伊万输入了一个长度为 n 的命令序列,机器人执行了该序列。执行完该序列后,机器人最终回到了起始格子 (0,0);但伊万怀疑该序列本身并不能保证正确执行后使机器人回到同一格子。他认为某些命令被机器人忽略了。为了判断机器人是否存在严重缺陷,他需要计算最多可能有多少条命令被正确执行。请帮助伊万完成这一计算!
输入格式
The first line contains one number n — the length of sequence of commands entered by Ivan (1 ≤ n ≤ 100).
The second line contains the sequence itself — a string consisting of n characters. Each character can be U, D, L or R.
第一行包含一个数字 n —— 伊万输入的命令序列的长度(1≤n≤100)。
第二行包含该序列本身 —— 一个由 n 个字符组成的字符串。每个字符可以是 U、D、L 或 R。
输出格式
Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.
输出机器人执行序列中的指令后最终回到起始格子时,所能执行的最多指令条数。
输入输出样例
输入#1
4 LDUR
输出#1
4
输入#2
5 RRRUU
输出#2
0
输入#3
6 LLRRRR
输出#3
4
输入解题思路,AI测评打分。不知道怎么写?