CF1578A.Anti-Tetris
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let us consider the game "Sticky Tetris". In this game, there is a field of n×m squares. Tiles appear on the field and the player can move the tiles.
Each tile is a 4-connected set of at most 7 squares.
Each new tile appears in any position that fits inside the field, does not intersect any other tile, and the top cell of the tile is at the top row of the field. The player can move the tile left, right, and down, and at any moment the tile must still entirely fit inside the field and must not intersect other tiles. The player can stop the tile at any position at any time. After that, it cannot be moved. Since this is "Sticky Tetris," the tile will not fall once stopped.
You are given a final configuration of a "Sticky Tetris" game. You need to restore a sequence of steps that leads to that configuration if it exists.
我们来考虑游戏“粘性俄罗斯方块”(Sticky Tetris)。该游戏有一个 n×m 的方格场地。方块会出现在场地上,玩家可以移动这些方块。
每个方块都是至多包含 7 个方格的四连通集合。
每个新方块出现时,其位置必须满足:完全位于场地上、不与其他已放置的方块相交,且该方块的最上方格位于场地的最顶行。玩家可将方块向左、向右或向下移动;在任意时刻,方块都必须完全位于场地上,且不能与其他方块相交。玩家可在任意时刻、任意位置停止方块下落。一旦停止,该方块便不可再移动。由于这是“粘性俄罗斯方块”,方块停止后不会继续下落。
你将获得一个“粘性俄罗斯方块”游戏的最终局面。若存在达成该局面的操作序列,请将其还原出来;否则判定为不存在。
输入格式
The first line contains two integers n and m (1≤n,m≤50) — the size of the playing field.
The next n lines contain a string of m characters each. Each character could be either a '.', or lowercase English letter. Connected components of the same letter correspond to a single tile. Each tile consists of at most 7 squares.
第一行包含两个整数 n 和 m(1≤n,m≤50)——表示游戏场地的尺寸。
接下来的 n 行,每行包含一个长度为 m 的字符串。每个字符要么是 '.',要么是小写英文字母。相同字母的连通块对应一个方块(tile)。每个方块最多由 7 个方格组成。
输出格式
If there is no solution, print −1.
Otherwise, print k — the number of different tiles that are placed on the field.
On the next k lines print the sequence of steps for each of the tiles in the order they are placed.
Each line consists of a number x followed by a string with steps. x (1≤x≤m) is the starting column of the leftmost square in the top row of the tile. The string consists of characters 'L' (for left), 'R' (for right), and 'D' (for down), describing the path of that tile, ending with a single character 'S' (for stop). The final position of the tile determines which tile is being placed. The string with steps can have at most n⋅m+1 characters.
如果没有解,输出 −1。
否则,输出 k —— 放置在棋盘上的不同方块的数量。
接下来的 k 行中,按方块放置的顺序,每行输出对应方块的移动步骤序列。
每行由一个数字 x 和一个表示移动步骤的字符串组成。x(1≤x≤m)表示该方块最上方一行中最左侧方格的起始列号。字符串由字符 'L'(向左)、'R'(向右)和 'D'(向下)组成,描述该方块的移动路径,最后以单个字符 'S'(停止)结尾。方块的最终位置决定了所放置的是哪一个方块。该步骤字符串最多包含 n⋅m+1 个字符。
输入输出样例
输入#1
3 2 aa ab aa
输出#1
2 2 DS 1 S
输入#2
5 6 ....dd .ccccd .cbbdd .aab.a aabbaa
输出#2
5 2 DDDS 4 DDLS 6 DDDS 2 DS 5 S
输入#3
5 3 ... aab abb aab .bb
输出#3
-1
输入解题思路,AI测评打分。不知道怎么写?