A8025 | Cutting Jigsaw Puzzle
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The Hedgehog recently remembered one of his favorite childhood activities, — solving puzzles, and got into it with new vigor. He would sit day in, day out with his friend buried into thousands of tiny pieces of the picture, looking for the required items one by one.
Soon the Hedgehog came up with a brilliant idea: instead of buying ready-made puzzles, one can take his own large piece of paper with some picture and cut it into many small rectangular pieces, then mix them and solve the resulting puzzle, trying to piece together the picture. The resulting task is even more challenging than the classic puzzle: now all the fragments have the same rectangular shape, and one can assemble the puzzle only relying on the picture drawn on the pieces.
All puzzle pieces turn out to be of the same size $X×Y$ , because the picture is cut first by horizontal cuts with the pitch of $X$ , then with vertical cuts with the pitch of $Y$ . If we denote the initial size of the picture as $A×B$ , then $A$ must be divisible by $X$ and $B$ must be divisible by $Y$ ( $X$ and $Y$ are integer numbers).
However, not every such cutting of the picture will result in a good puzzle. The Hedgehog finds a puzzle good if no two pieces in it are the same (It is allowed to rotate the pieces when comparing them, but it is forbidden to turn them over).
Your task is to count for a given picture the number of good puzzles that you can make from it, and also to find the puzzle with the minimal piece size.
Soon the Hedgehog came up with a brilliant idea: instead of buying ready-made puzzles, one can take his own large piece of paper with some picture and cut it into many small rectangular pieces, then mix them and solve the resulting puzzle, trying to piece together the picture. The resulting task is even more challenging than the classic puzzle: now all the fragments have the same rectangular shape, and one can assemble the puzzle only relying on the picture drawn on the pieces.
All puzzle pieces turn out to be of the same size $X×Y$ , because the picture is cut first by horizontal cuts with the pitch of $X$ , then with vertical cuts with the pitch of $Y$ . If we denote the initial size of the picture as $A×B$ , then $A$ must be divisible by $X$ and $B$ must be divisible by $Y$ ( $X$ and $Y$ are integer numbers).
However, not every such cutting of the picture will result in a good puzzle. The Hedgehog finds a puzzle good if no two pieces in it are the same (It is allowed to rotate the pieces when comparing them, but it is forbidden to turn them over).
Your task is to count for a given picture the number of good puzzles that you can make from it, and also to find the puzzle with the minimal piece size.
输入格式
The first line contains two numbers $A$ and $B$ which are the sizes of the picture. They are positive integers not exceeding 20.
Then follow $A$ lines containing $B$ symbols each, describing the actual picture. The lines only contain uppercase English letters.
Then follow $A$ lines containing $B$ symbols each, describing the actual picture. The lines only contain uppercase English letters.
输出格式
In the first line print the number of possible good puzzles (in other words, the number of pairs $(X,Y)$ such that the puzzle with the corresponding element sizes will be good). This number should always be positive, because the whole picture is a good puzzle itself.
In the second line print two numbers — the sizes $X$ and $Y$ of the smallest possible element among all good puzzles. The comparison is made firstly by the area $XY$ of one element and secondly — by the length $X$ .
In the second line print two numbers — the sizes $X$ and $Y$ of the smallest possible element among all good puzzles. The comparison is made firstly by the area $XY$ of one element and secondly — by the length $X$ .
输入输出样例
输入 #1
2 4 ABDC ABDC
输出 #1
3 2 1
输入 #2
2 6 ABCCBA ABCCBA
输出 #2
1 2 6
The picture in the first sample test has the following good puzzles: $(2,1)$ , $(2,2)$ , $(2,4)$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted