#P10475. [USACO03FALL] Milking Grid(数据加强版)

    ID: 11810 远端评测题 1000ms 512MiB 尝试: 1 已通过: 1 显示难度普及+/提高− 上传者: 标签>USACO哈希 hashingKMP 算法

[USACO03FALL] Milking Grid(数据加强版)

Problem Description

Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R(1R10,000)R (1 \leq R \leq 10,000) rows by C(1C75)C (1 \leq C \leq 75) columns. As we all know, Farmer John is quite the expert on cow behavior, and is currently writing a book about feeding behavior in cows. He notices that if each cow is labeled with an uppercase letter indicating its breed, the two-dimensional pattern formed by his cows during milking sometimes seems to be made from smaller repeating rectangular patterns.

Help FJ find the rectangular unit of smallest area that can be repetitively tiled to make up the entire milking grid. Note that the dimensions of the small rectangular unit do not necessarily need to divide evenly the dimensions of the entire milking grid, as indicated in the sample input below.

Input Format

  • Line 11: Two space-separated integers: RR and CC

  • Lines 2R+12\dots R+1: The grid that the cows form, with an uppercase letter denoting each cow's breed. Each of the RR input lines has CC characters with no space or other intervening character.

Output Format

  • Line 1: The area of the smallest unit from which the grid is formed
2 5 
ABABA 
ABABA

2

Hint

The entire milking grid can be constructed from repetitions of the pattern AB.