CF54B.Cutting Jigsaw Puzzle
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
刺猬最近想起了自己童年时最喜爱的活动之一——解拼图,并以全新的热情投入其中。他日复一日地与朋友坐在一起,面对成千上万个微小的图片碎片,逐一寻找所需的部分。
很快,刺猬想出了一个绝妙的主意:与其购买现成的拼图,不如取一张自己拥有的、带有图案的大纸,将其裁剪成许多大小相同的小矩形碎片,再将它们打乱,然后尝试重新拼回原图。这样得到的任务比经典拼图更具挑战性:此时所有碎片形状完全相同(均为矩形),而拼合过程只能依赖于各碎片上所绘制的图案信息。
所有拼图碎片最终尺寸均为 X×Y,这是因为原图首先沿水平方向以间距 X 进行切割,再沿垂直方向以间距 Y 进行切割。若记原图尺寸为 A×B,则 A 必须能被 X 整除,且 B 必须能被 Y 整除(其中 X 和 Y 均为正整数)。
然而,并非所有满足上述条件的裁剪方式都能生成一个“好”的拼图。刺猬认为一个拼图是“好”的,当且仅当其中任意两块碎片均不相同(比较碎片是否相同时允许旋转,但禁止翻面)。
你的任务是:对于给定的图片,计算可从中构造出的“好”拼图的总数,并找出其中碎片尺寸最小的那个拼图。
输入格式
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.
第一行包含两个数字 A 和 B,表示图片的尺寸。它们是不超过 20 的正整数。
接下来是 A 行,每行包含 B 个字符,描述实际的图片。各行仅包含大写英文字母。
输出格式
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.
第一行输出可能的“好谜题”的数量(即满足对应元素尺寸的谜题为“好谜题”的有序对 (X,Y) 的个数)。该数值恒为正,因为整幅图像本身即构成一个“好谜题”。
第二行输出两个数——在所有“好谜题”中,单个元素的最小可能尺寸 X 和 Y。比较规则为:首先按单个元素的面积 XY 升序排列,面积相同时再按长度 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).
第一个样例测试中的图片包含以下合法谜题:(2,1)、(2,2)、(2,4)。
输入解题思路,AI测评打分。不知道怎么写?