54B

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.

Input

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.

Output

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.

Examples

Input

2 4ABDCABDC

Output

32 1

Input

2 6ABCCBAABCCBA

Output

12 6
111枚举边长,然后枚举每个子方块,用hash检查
#include<iostream>
#include<set>
#include<cstdio>
using namespace std;
typedef long long ll;
char board[30][30];
set<ll>used;
int A,B,ans,x,y;
bool check(int x,int y)
{
	used.clear();
	int t1=A/x,t2=B/y;
	for(int i=1;i<=t1;i++)for(int j=1;j<=t2;j++)
	{
		ll temp[5];
		int cnt=0;
		for(int i=1;i<5;i++) temp[i]=0;
		++cnt;
		for(int ii=1;ii<=x;ii++)for(int jj=1;jj<=y;jj++)
		{
			temp[cnt]*=171;
			temp[cnt]+=board[(i-1)*x+ii][(j-1)*y+jj];
		}
		++cnt;
		for(int ii=x;ii>=1;ii--)for(int jj=y;jj>=1;jj--)
		{
			temp[cnt]*=171;
			temp[cnt]+=board[(i-1)*x+ii][(j-1)*y+jj];
		}
		++cnt;
		if(x==y)
		{
			for(int jj=y;jj>=1;jj--)for(int ii=1;ii<=x;ii++)
			{
				temp[cnt]*=171;
				temp[cnt]+=board[(i-1)*x+ii][(j-1)*y+jj];
			}
			++cnt;
			for(int jj=x;jj>=1;jj--)for(int ii=1;ii<=y;ii++)
			{
				temp[cnt]*=171;
				temp[cnt]+=board[(i-1)*x+ii][(j-1)*y+jj];
			}
			++cnt;
		}
		for(int k=1;k<cnt;k++) if(used.count(temp[k])) return false;
		for(int k=1;k<cnt;k++) used.insert(temp[k]);
	}
	return true;
}
int main()
{
	cin>>A>>B;
	for(int i=1;i<=A;i++)
	{
		for(int j=1;j<=B;j++)
			cin>>board[i][j];
	}
	x=y=1<<10;
	for(int i=A;i>=1;i--)for(int j=B;j>=1;j--)
	{
		if(A%i==0&&B%j==0) if(check(i,j))
		{
			ans++;
//			cout<<i<<" "<<j<<endl;
			if(i*j<x*y) {x=i;y=j;}
			else if(i*j==x*y) if(i<x){x=i;y=j;}
		}
	}
	cout<<ans<<endl;
	cout<<x<<" "<<y<<endl;
	return 0;
}
时间: 2024-08-24 08:03:17

54B的相关文章

Linking code for an enhanced application binary interface (ABI) with decode time instruction optimization

A code sequence made up multiple instructions and specifying an offset from a base address is identified in an object file. The offset from the base address corresponds to an offset location in a memory configured for storing an address of a variable

Snoop resynchronization mechanism to preserve read ordering

A processor employing a post-cache (LS2) buffer. Loads are stored into the LS2buffer after probing the data cache. The load/store unit snoops the loads in the LS2?buffer against snoop requests received from an external bus. If a snoop invalidate requ

ZIP压缩算法详细分析及解压实例解释

最近自己实现了一个ZIP压缩数据的解压程序,觉得有必要把ZIP压缩格式进行一下详细总结,数据压缩是一门通信原理和计算机科学都会涉及到的学科,在通信原理中,一般称为信源编码,在计算机科学里,一般称为数据压缩,两者本质上没啥区别,在数学家看来,都是映射.一方面在进行通信的时候,有必要将待传输的数据进行压缩,以减少带宽需求:另一方面,计算机存储数据的时候,为了减少磁盘容量需求,也会将文件进行压缩,尽管现在的网络带宽越来越高,压缩已经不像90年代初那个时候那么迫切,但在很多场合下仍然需要,其中一个原因是

存储模型(下)

程序的局部性: 程序在执行过程中的一个较短时期,所执行的指令地址和指令的操作数地址,分别局限于一定区域 时间局部性一条指令的一次执行和下次执行,一个数据的一次访问和下次访问都集中在一个较短时期内空间局部性当前指令和邻近的几条指令,当前访问的数据和邻近的几个数据都集中在一个较小区域内分支局部性一条跳转指令的两次执行,很可能跳到相同的内存位置 例子: 页面大小为4K,分配给每个进程的物理页面数为1.在一个进程中,定义了如下的二维数组int A[1024][1024],该数组按行存放在内存,每一行放在

End-to end provisioning of storage clouds

Embodiments discussed in this disclosure provide an integrated provisioning framework that automates the process of provisioning storage resources, end-to-end, for an enterprise storage cloud environment. Such embodiments configure and orchestrate th

三极管参数应用大全(转载)

BU2525AF NPN 30 开关 功放 1500V12A150W /350NSBU2525AX NPN 30 开关 功放 1500V12A150W /350NSBU2527AF NPN 30 开关 功放 1500V15A150WBU2532AW NPN 30 开关 功放 1500V15A150W(大屏)BUH515 NPN BCE 行管 1500V10A80WBUH515D NPN BCE 行管 1500V10A80W(带阻尼)BUS13A NPN 12 开关 功放 1000V15A175W

Multi-core compute cache coherency with a release consistency memory ordering model

A method includes storing, with a first programmable processor, shared variable data to cache lines of a first cache of the first processor. The method further includes executing, with the first programmable processor, a store-with-release operation,

删数字(华为笔试题)

Be4m83寿qyo履谡4http://www.docin.com/app/user/userinfo?userid=179253696 cp那8泌qg捣腿6sihttp://www.facebolw.com/space/2103619/follower 3傅2派O9捣枪幼2赝http://jz.docin.com/hfzi26050 甲4n97FVL焙9侗Xhttp://shequ.docin.com/rurf998 j8f3HX识9县Jhttp://shufang.docin.com/thf

漫漫运维路——各种加密方式介绍及基于OpenSSL实现HTTPS

一.为什么要加密 在网络中通信有时通信双方会发送一些比较敏感的信息,如果直接明文在网上传输,就可能被居心叵测的人截获,从而达到其非法的目的.为保证通信双方信息传输不被第三方所知晓,使用加密技术把双方传输的数据进行加密,即使数据被第三方所截获,那么第三方也不会知晓其数据的真实含义.在此,通信双方所交换的信息中,未被加密的数据称为明文,而加密后的数据称为密文,加密采用的方式称作加密密钥. 二.常见加密方式以及其用途 对称加密 对称加密是指在加密通信过程中,把明文加密为密文的密钥和把密文解密为明文的密