CF1607F.Robot on the Board 2

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The robot is located on a checkered rectangular board of size n×mn \times m (nn rows, mm columns). The rows in the board are numbered from 11 to nn from top to bottom, and the columns — from 11 to mm from left to right.

The robot is able to move from the current cell to one of the four cells adjacent by side.

Each cell has one of the symbols 'L', 'R', 'D' or 'U' written on it, indicating the direction in which the robot will move when it gets in that cell — left, right, down or up, respectively.

The robot can start its movement in any cell. He then moves to the adjacent square in the direction indicated on the current square in one move.

  • If the robot moves beyond the edge of the board, it falls and breaks.
  • If the robot appears in the cell it already visited before, it breaks (it stops and doesn't move anymore).

Robot can choose any cell as the starting cell. Its goal is to make the maximum number of steps before it breaks or stops.

Determine from which square the robot should start its movement in order to execute as many commands as possible. A command is considered successfully completed if the robot has moved from the square on which that command was written (it does not matter whether to another square or beyond the edge of the board).

机器人位于一个 n×mn \times m(nn 行,mm 列)的方格矩形棋盘上。棋盘的行从上到下编号为 11 至 nn,列从左到右编号为 11 至 mm。

机器人可以从当前格子移动到四个与之边相邻的格子之一。

每个格子上标有一个字符:'L'、'R'、'D' 或 'U',分别表示当机器人进入该格子时将要移动的方向:左、右、下、上。

机器人可任选一个格子作为起始位置,然后在每一步中,根据当前所在格子上所标注的方向,向相邻格子移动一格。

  • 若机器人移出棋盘边界,则会坠落并损坏;
  • 若机器人进入一个它之前已访问过的格子,则会损坏(即停止运行,不再移动)。

机器人可任选一个格子作为起始格子。其目标是在损坏或停止前,尽可能多地执行移动步数。

请确定机器人应从哪个格子出发,才能执行最多的指令。若机器人从某格子(该格子上写有某条指令)出发并执行了该指令(即从该格子移出,无论移向另一格子还是移出棋盘边界),则该指令即视为成功执行。

输入格式

The first line contains an integer tt (1≤t≤100001 \le t \le 10000) — the number of test cases in the test.

Each test case's description is preceded by a blank line. Next is a line that contains integers nn and mm (1≤n≤20001 \le n \le 2000; 1≤m≤20001 \le m \le 2000) — the height and width of the board. This line followed by nn lines, the ii-th of which describes the ii-th line of the board. Each of them is exactly mm letters long and consists of symbols 'L', 'R', 'D' and 'U'.

It is guaranteed that the sum of sizes of all boards in the input does not exceed 4⋅1064\cdot10^6.

第一行包含一个整数 tt(1≤t≤100001 \le t \le 10000)—— 表示测试用例的数量。

每个测试用例的描述前均有一空行。接下来是一行,包含两个整数 nn 和 mm(1≤n≤20001 \le n \le 2000;1≤m≤20001 \le m \le 2000)—— 分别表示棋盘的高度与宽度。随后是 nn 行,其中第 ii 行描述棋盘的第 ii 行。每行恰好由 mm 个字符组成,且仅包含字符 'L'、'R'、'D' 和 'U'。

保证输入中所有棋盘的尺寸总和不超过 4⋅1064\cdot10^6。

输出格式

For each test case, output three integers rr, cc and dd (1≤r≤n1 \le r \le n; 1≤c≤m1 \le c \le m; d≥0d \ge 0), which denote that the robot should start moving from cell (r,c)(r, c) to make the maximum number of moves dd. If there are several answers, output any of them.

对于每个测试用例,输出三个整数 rr、cc 和 dd(1≤r≤n1 \le r \le n;1≤c≤m1 \le c \le m;d≥0d \ge 0),表示机器人应从单元格 (r,c)(r, c) 出发,以实现最大移动步数 dd。若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    7
    
    1 1
    R
    
    1 3
    RRL
    
    2 2
    DL
    RU
    
    2 2
    UD
    RU
    
    3 2
    DL
    UL
    RU
    
    4 4
    RRRD
    RUUD
    URUD
    ULLR
    
    4 4
    DDLU
    RDDU
    UUUU
    RDLD

    输出#1

    1 1 1
    1 1 3
    1 1 4
    2 1 3
    3 1 5
    4 3 12
    1 1 4

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

首页