102252: [AtCoder]ABC225 C - Calendar Validator

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

There is a $10^{100} \times 7$ matrix $A$, where the $(i,j)$-th entry is $(i-1) \times 7 + j$ for every pair of integers $(i,j)\ (1 \leq i \leq 10^{100}, 1 \leq j \leq 7)$.

Given an $N \times M$ matrix $B$, determine whether $B$ is some (unrotated) rectangular part of $A$.

Constraints

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

Input

Input is given from Standard Input in the following format:

$N$ $M$
$B_{1,1}$ $B_{1,2}$ $\ldots$ $B_{1,M}$
$B_{2,1}$ $B_{2,2}$ $\ldots$ $B_{2,M}$
$\hspace{1.6cm}\vdots$
$B_{N,1}$ $B_{N,2}$ $\ldots$ $B_{N,M}$

Output

If $B$ is some rectangular part of $A$, print Yes; otherwise, print No.


Sample Input 1

2 3
1 2 3
8 9 10

Sample Output 1

Yes

The given matrix $B$ is the top-left $2 \times 3$ submatrix of $A$.


Sample Input 2

2 1
1
2

Sample Output 2

No

Although the given matrix $B$ would match the top-left $1 \times 2$ submatrix of $A$ after rotating $90$ degrees, the Problem Statement asks whether $B$ is an unrotated part of $A$, 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

Input

题意翻译

有一个 $10^{100}$ 行 $7$ 列的大方阵,位于 $(i,j)$ (上起第 $i$ 行,左起第 $j$ 列)的数为 $7×(i-1)+j$ 。现在给出一个 $n$ 行 $m$ 列的小方阵,问该方阵是否为前面所述的大方阵的一部分。( $1≤n≤10^4$ , $1≤m≤7$ ,方阵中的每个数都是正整数,它们的值都不会大于 $10^9$ )**(方向不变)**

Output

得分:300分

问题描述

有一个大小为$10^{100} \times 7$的矩阵$A$,其中对于每对整数$(i,j)\ (1 \leq i \leq 10^{100}, 1 \leq j \leq 7)$,第$(i,j)$个元素是$(i-1) \times 7 + j$。

给定一个大小为$N \times M$的矩阵$B$,判断$B$是否是$A$的某个(未旋转)矩形部分。

限制条件

  • $1 \leq N \leq 10^4$
  • $1 \leq M \leq 7$
  • $1 \leq B_{i,j} \leq 10^9$
  • 输入中的所有值都是整数。

输入

从标准输入按照以下格式获取输入:

$N$ $M$
$B_{1,1}$ $B_{1,2}$ $\ldots$ $B_{1,M}$
$B_{2,1}$ $B_{2,2}$ $\ldots$ $B_{2,M}$
$\hspace{1.6cm}\vdots$
$B_{N,1}$ $B_{N,2}$ $\ldots$ $B_{N,M}$

输出

如果$B$是$A$的某个矩形部分,打印Yes;否则,打印No


样例输入1

2 3
1 2 3
8 9 10

样例输出1

Yes

给定的矩阵$B$是矩阵$A$的左上角$2 \times 3$子矩阵。


样例输入2

2 1
1
2

样例输出2

No

虽然给定的矩阵$B$在旋转90度后会匹配到$A$的左上角$1 \times 2$子矩阵,但问题描述要求$B$是$A$的未旋转部分,因此答案为No


样例输入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

样例输出3

Yes

加入题单

算法标签: