CF1080E.Sonya and Matrix Beauty
提高+/省选-
通过率:0%
时间限制:1.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Sonya had a birthday recently. She was presented with the matrix of size n×m and consist of lowercase Latin letters. We assume that the rows are numbered by integers from 1 to n from bottom to top, and the columns are numbered from 1 to m from left to right.
Let's call a submatrix (i1,j1,i2,j2) (1≤i1≤i2≤n;1≤j1≤j2≤m) elements aij of this matrix, such that i1≤i≤i2 and j1≤j≤j2. Sonya states that a submatrix is beautiful if we can independently reorder the characters in each row (not in column) so that all rows and columns of this submatrix form palidroms.
Let's recall that a string is called palindrome if it reads the same from left to right and from right to left. For example, strings abacaba,bcaacb,a are palindromes while strings abca,acbba,ab are not.
Help Sonya to find the number of beautiful submatrixes. Submatrixes are different if there is an element that belongs to only one submatrix.
索尼娅最近过生日了。她收到了一个大小为 n×m 的矩阵,其中每个元素均为小写拉丁字母。我们约定:行编号从下到上依次为 1 到 n,列编号从左到右依次为 1 到 m。
我们将满足 1≤i1≤i2≤n 且 1≤j1≤j2≤m 的四元组 (i1,j1,i2,j2) 称为一个子矩阵,它包含原矩阵中所有满足 i1≤i≤i2 且 j1≤j≤j2 的元素 aij。索尼娅定义:若一个子矩阵可以通过独立地对每一行内的字符重新排列(不允许对列重排),使得该子矩阵的每一行和每一列都成为回文串,则称该子矩阵是“优美的”。
我们回顾:若一个字符串从左向右读与从右向左读完全相同,则称其为回文串。例如,字符串 abacaba、bcaacb、a 是回文串,而 abca、acbba、ab 不是回文串。
请帮助索尼娅计算优美子矩阵的个数。若两个子矩阵至少有一个元素只属于其中之一,则认为它们是不同的子矩阵。
输入格式
The first line contains two integers n and m (1≤n,m≤250) — the matrix dimensions.
Each of the next n lines contains m lowercase Latin letters.
第一行包含两个整数 n 和 m(1≤n,m≤250)——矩阵的维度。
接下来的 n 行,每行包含 m 个小写拉丁字母。
输出格式
Print one integer — the number of beautiful submatrixes.
输出一个整数——美丽子矩阵的数量。
输入输出样例
输入#1
1 3 aba
输出#1
4
输入#2
2 3 aca aac
输出#2
11
输入#3
3 5 accac aaaba cccaa
输出#3
43
说明/提示
In the first example, the following submatrixes are beautiful: ((1,1),(1,1));((1,2),(1,2)); ((1,3),(1,3));((1,1),(1,3)).
In the second example, all submatrixes that consist of one element and the following are beautiful: ((1,1),(2,1)); ((1,1),(1,3));((2,1),(2,3));((1,1),(2,3));((2,1),(2,2)).
Some of the beautiful submatrixes are: ((1,1),(1,5));((1,2),(3,4)); ((1,1),(3,5)).
The submatrix ((1,1),(3,5)) is beautiful since it can be reordered as:
accca
aabaa
accca
In such a matrix every row and every column form palindromes.
在第一个例子中,以下子矩阵是优美的:((1,1),(1,1));((1,2),(1,2)); ((1,3),(1,3));((1,1),(1,3))。
在第二个例子中,所有仅含一个元素的子矩阵,以及以下子矩阵是优美的:((1,1),(2,1)); ((1,1),(1,3));((2,1),(2,3));((1,1),(2,3));((2,1),(2,2))。
一些优美的子矩阵包括:((1,1),(1,5));((1,2),(3,4)); ((1,1),(3,5))。
子矩阵 ((1,1),(3,5)) 是优美的,因为它可以重排为:
accca
aabaa
accca
在此矩阵中,每一行和每一列均构成回文。
输入解题思路,AI测评打分。不知道怎么写?