#abc225c. C - Calendar Validator

C - Calendar Validator

Score : 300300 points

问题描述

存在一个大小为 10100×710^{100} \times 7 的矩阵 AA,对于所有整数对 (i,j)(i,j)(满足 1i101001 \leq i \leq 10^{100}1j71 \leq j \leq 7),其第 (i,j)(i,j) 个元素为 (i1)×7+j(i-1) \times 7 + j

给定一个 N×MN \times M 矩阵 BB,确定 BB 是否是矩阵 AA 的某个(未旋转的)矩形部分。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a 10100×710^{100} \times 7 matrix AA, where the (i,j)(i,j)-th entry is (i1)×7+j(i-1) \times 7 + j for every pair of integers (i,j) (1i10100,1j7)(i,j)\ (1 \leq i \leq 10^{100}, 1 \leq j \leq 7).

Given an N×MN \times M matrix BB, determine whether BB is some (unrotated) rectangular part of AA.

Constraints

  • 1N1041 \leq N \leq 10^4
  • 1M71 \leq M \leq 7
  • 1Bi,j1091 \leq B_{i,j} \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

B1,1B_{1,1} B1,2B_{1,2} \ldots B1,MB_{1,M}

B2,1B_{2,1} B2,2B_{2,2} \ldots B2,MB_{2,M}

\hspace{1.6cm}\vdots

BN,1B_{N,1} BN,2B_{N,2} \ldots BN,MB_{N,M}

Output

If BB is some rectangular part of AA, print Yes; otherwise, print No.

Sample Input 1

2 3
1 2 3
8 9 10

Sample Output 1

Yes

The given matrix BB is the top-left 2×32 \times 3 submatrix of AA.

Sample Input 2

2 1
1
2

Sample Output 2

No

Although the given matrix BB would match the top-left 1×21 \times 2 submatrix of AA after rotating 9090 degrees, the Problem Statement asks whether BB is an unrotated part of AA, so the answer is No.

Sample Input 3

10 4
1346 1347 1348 1349
1353 1354 1355 1356
1360 1361 1362 1363
1367 1368 1369 1370
1374 1375 1376 1377
1381 1382 1383 1384
1388 1389 1390 1391
1395 1396 1397 1398
1402 1403 1404 1405
1409 1410 1411 1412

Sample Output 3

Yes

update @ 2024/3/10 09:53:01