P26372 [AtCoder] Redecorating
NOI
题目描述

Problem Description

As December begins and 2014 is about to end, we decided to freshen up our mood by redecorating our wallpaper to welcome 2015.

We have a fabric of R rows and C columns, and we decided to cut out a design from this fabric for our wallpaper, if necessary.

When cutting out the design, we must always cut along the grid lines, and the design must be rectangular in shape.

Each cell in the fabric is painted in exactly one color.

We always pursue interesting designs, so this year, we decided to create a stencil for a "point-symmetric design".

A design is considered "point-symmetric" if, given its size of H rows and W columns:

  • It satisfies H ≧ 2 and W ≧ 2.
  • For all integers i, j (1 ≦ i ≦ H, 1 ≦ j ≦ W), the color c_{i,j} of the cell at the i-th row from the top and j-th column from the left is equal to the color c_{H-i+1,W-j+1} of the cell at the (H-i+1)-th row from the top and (W-j+1)-th column from the left.

Due to the interesting aspects of the fabric other than color, even if the size and color arrangement are exactly the same, cutting from different locations results in different designs. We want to know how many ways there are to cut out a "point-symmetric design" from the fabric.

Input Format

The input is given from the standard input in the following format:

R C s_1 s_2 : s_R

  • The first line contains the number of rows R (1 ≦ R ≦ 250) and columns C (1 ≦ C ≦ 250) of the fabric, separated by a space.
  • The next R lines contain information about the color scheme of the fabric. The i-th line (1 ≦ i ≦ R) contains a string s_i of length C. s_i is composed of lowercase English letters, where the j-th character (1 ≦ j ≦ C) represents the color of the cell at the i-th row from the top and j-th column from the left.
  • For any two different cells, if the characters representing their colors are the same, they are painted the same color; otherwise, they are painted different colors.

Output Format

Output the number of "point-symmetric designs" on one line. Ensure a newline at the end of the output.

Sample Input and Output

Sample Input #1

2 10
codethanks
documentsk

Sample Output #1

2

Sample Input #2

6 4
aaaa
abba
abba
aaaa
ccbb
cdbb

Sample Output #2

5

Notes/Hints

Partial Points

This problem has partial points:

  • For dataset 1 where R ≦ 20 and C ≦ 20, getting all correct answers awards 15 points.
  • For dataset 2 where R ≦ 100 and C ≦ 100, getting all correct answers awards an additional 30 points.
  • For dataset 3 without additional constraints, getting all correct answers awards an additional 55 points, totaling 100 points.

Sample Explanation 1

The color scheme of the fabric is as follows:

c o d e t h a n k s
d o c u m e n t s k

For example, cutting out a region of 2 rows and 3 columns with the top-left cell at the 1st row and 1st column, and the bottom-right cell at the 2nd row and 3rd column results in:

c o d
d o c

which is a "point-symmetric design". There is another place where such a design can be cut out, so the answer is 2.

Sample Explanation 2

Even if a "point-symmetric design" contains another "point-symmetric design", they are counted separately. Also, in this example, "bbbb" appears in two places, and both are counted.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 10 codethanks documentsk
样例输出
2