#GL0000378. Nén ma trận nhị phân (Compression)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nén ma trận nhị phân (Compression)
Compression
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a binary matrix of size , whose cells contain only and .
A positive integer is a valid compression factor if divides and the matrix can be partitioned into non-overlapping square blocks within each of which every cell has the same value. Such a block can be represented by a single cell in an matrix.
Find the largest possible . Compression factor is always valid.
To save input space, each matrix row is encoded as a hexadecimal string of length . Every character 0–9 or A–F represents exactly four consecutive bits from left to right. For example, B is 1011 and 5 is 0101. There are no spaces within a row.
Input
The first line contains , a multiple of . The next lines each contain one uppercase hexadecimal string of exactly characters.
Output
Print the maximum valid integer compression factor .
Subtasks
-
Subtask 1 (20 points): , ; mỗi dòng có đúng ký tự hex.
-
Subtask 2 (30 points): , ; mỗi dòng có đúng ký tự hex.
-
Subtask 3 (50 points): , ; mỗi dòng có đúng ký tự hex.
Examples
Example 1
Input
8
E7
E7
E7
00
00
E7
E7
E7
Output
1
Explanation
Hex E7 expands to 11100111 and 00 to 00000000. The changes in cell values do not align with boundaries of constant blocks; hence the largest factor is .
Example 2
Input
4
7
F
F
F
Output
1
Explanation
The first row is 0111, while the remaining rows are 1111. The upper-left block contains both and , and the entire matrix is not constant. Only works.
Example 3
Input
4
F
F
F
F
Output
4
Explanation
All 16 cells are , so the whole matrix forms a constant block; the answer is .