A14487 | Anti-Tetris
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Let us consider the game "Sticky Tetris". In this game, there is a field of $n \times 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.
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.
输入格式
The first line contains two integers $n$ and $m$ ( $1 \le n, m \le 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.
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.
输出格式
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 \le x \le 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 \cdot m + 1$ characters.
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 \le x \le 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 \cdot m + 1$ characters.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted