CF89C.Chip Play
提高+/省选-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's consider the following game. We have a rectangular field n × m in size. Some squares of the field contain chips.
Each chip has an arrow painted on it. Thus, each chip on the field points in one of the following directions: up, down, left or right.
The player may choose a chip and make a move with it.
The move is the following sequence of actions. The chosen chip is marked as the current one. After that the player checks whether there are more chips in the same row (or in the same column) with the current one that are pointed by the arrow on the current chip. If there is at least one chip then the closest of them is marked as the new current chip and the former current chip is removed from the field. After that the check is repeated. This process can be repeated several times. If a new chip is not found, then the current chip is removed from the field and the player's move ends.
By the end of a move the player receives several points equal to the number of the deleted chips.
By the given initial chip arrangement determine the maximum number of points that a player can receive during one move. Also determine the number of such moves.
我们来考虑如下游戏:有一个大小为 n×m 的矩形棋盘,棋盘上某些格子中放置有棋子。
每个棋子上都画有一个箭头,因此每个棋子所指方向为上、下、左、右四个方向之一。
玩家可任选一个棋子并对其执行一次移动操作。
该移动操作按如下步骤进行:首先将所选棋子标记为“当前棋子”。接着,玩家检查在当前棋子所在的同一行(若箭头指向左或右)或同一列(若箭头指向上或下)中,是否存在其他被当前棋子箭头所指向的棋子。若存在至少一个这样的棋子,则将其中距离当前棋子最近的一个标记为新的“当前棋子”,同时将原来的当前棋子从棋盘上移除。随后重复上述检查过程。此过程可重复多次。若某次检查未找到符合条件的新棋子,则将当前棋子从棋盘上移除,本次移动操作结束。
一次移动操作结束时,玩家获得的分数等于此次操作中被删除的棋子总数。
给定初始棋子布局,请确定玩家在一次移动中所能获得的最大分数,以及能达到该最大分数的不同移动操作的数目。
输入格式
The first line contains two integers n and m (1 ≤ n, m, n × m ≤ 5000). Then follow n lines containing m characters each — that is the game field description. "." means that this square is empty. "L", "R", "U", "D" mean that this square contains a chip and an arrow on it says left, right, up or down correspondingly.
It is guaranteed that a field has at least one chip.
第一行包含两个整数 n 和 m(1≤n,m,n×m≤5000)。随后是 n 行,每行包含 m 个字符——即游戏场地的描述。
“.” 表示该格子为空;
“L”、“R”、“U”、“D” 表示该格子上有一个棋子,其上的箭头分别指向左、右、上、下。
保证场地上至少有一个棋子。
输出格式
Print two numbers — the maximal number of points a player can get after a move and the number of moves that allow receiving this maximum number of points.
输出两个数——玩家在一次移动后所能获得的最多分数,以及能够获得该最高分数的移动种数。
输入输出样例
输入#1
4 4 DRLD U.UL .UUR RDDL
输出#1
10 1
输入#2
3 5 .D... RRRLL .U...
输出#2
6 2
说明/提示
In the first sample the maximum number of points is earned by the chip in the position (3, 3). You can see its progress at the following picture:

All other chips earn fewer points.
在第一个样例中,位于位置 (3,3) 的棋子获得的分数最多。其移动过程如下图所示:

其余所有棋子获得的分数均更少。
输入解题思路,AI测评打分。不知道怎么写?