| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 10 초 | 1024 MB | 0 | 0 | 0 | 0.000% |
Chris is a fan of puzzles. Recently he learned about Sudoku puzzles, that are based on Latin squares. A $k \times k$ table is called a Latin square if the number of distinct elements in the table is $k$, and there are no two equal elements in the matrix that share the same row or the same column.
For example, ,
and
are Latin squares, while
,
and
are not.
Chris wants to make a new Latin square puzzle. However, he only has an old template, which is an $n \times m$ table. Chris wants to cut a contiguous Latin square fragment from the template. In how many ways can he do this? Two ways to cut a square are considered different if there is a cell that is present in one square, but not present in the other.
The first line contains two integers $n$ and $m$ --- dimensions of the template ($1 \le n, m \le 2\,000$).
The next $n$ lines contain strings $s_i$ that describe the template. Each string $s_i$ contains $2 \cdot m$ characters with ASCII codes between $33$ and $126$. The cell in row $i$ and column $j$ of the template contains a pair of characters $s_{i, 2 \cdot j - 1}$ and $s_{i, 2 \cdot j}$ ($1 \le i \le n$, $1 \le j \le m$). Two cells of the template contain equal elements if their ordered character pairs are equal. See the Notes section for further explanation.
Print a single integer --- the number of ways to cut a Latin square from the template.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 9 | $n, m \le 20$ |
| 2 | 10 | $n, m \le 100$ |
| 3 | 25 | $n, m \le 500$ |
| 4 | 26 | Elements in each row and each column are distinct. |
| 5 | 30 |
4 5 AABBAAAACC BBAABBCCAA AABBCCAABB BBCCAABBCC
26
5 10
!"#$%&'()*+,-./01234
56789:;<=>?@ABCDEFGH
IJKLMNOPQRSTUVWXYZ[\
]^_`abcdefghijklmnop
qrstuvwxyz{|}~!"#$%&
50
In the first sample there are $20$ ways to cut a $1 \times 1$ Latin square, as well as $6$ other ways:
| (a) Way 1 | (b) Way 2 | (c) Way 3 |
| (d) Way 4 | (e) Way 5 | (f) Way 6 |
Olympiad > Moscow Open Olympiad in Informatics > Moscow Open Olympiad in Informatics 2019-20 > Day 2 Rio de Janeiro번