CF1426B.Symmetric Matrix

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Masha has nn types of tiles of size 2×22 \times 2. Each cell of the tile contains one integer. Masha has an infinite number of tiles of each type.

Masha decides to construct the square of size m×mm \times m consisting of the given tiles. This square also has to be a symmetric with respect to the main diagonal matrix, and each cell of this square has to be covered with exactly one tile cell, and also sides of tiles should be parallel to the sides of the square. All placed tiles cannot intersect with each other. Also, each tile should lie inside the square. See the picture in Notes section for better understanding.

Symmetric with respect to the main diagonal matrix is such a square ss that for each pair (i,j)(i, j) the condition s[i][j]=s[j][i]s[i][j] = s[j][i] holds. I.e. it is true that the element written in the ii-row and jj-th column equals to the element written in the jj-th row and ii-th column.

Your task is to determine if Masha can construct a square of size m×mm \times m which is a symmetric matrix and consists of tiles she has. Masha can use any number of tiles of each type she has to construct the square. Note that she can not rotate tiles, she can only place them in the orientation they have in the input.

You have to answer tt independent test cases.

玛莎有 nn 种尺寸为 2×22 \times 2 的瓷砖。每块瓷砖的每个单元格中包含一个整数。玛莎拥有每种瓷砖的无限多个。

玛莎决定用给定的瓷砖拼出一个大小为 m×mm \times m 的正方形。该正方形还必须是一个关于主对角线对称的矩阵,且正方形中的每个单元格必须恰好被一块瓷砖的一个单元格所覆盖;同时,所有瓷砖的边必须与正方形的边平行。所有已放置的瓷砖彼此不能相交,且每块瓷砖必须完全位于正方形内部。详见“注释”部分的图示以帮助理解。

关于主对角线对称的矩阵是指:对于任意下标对 (i,j)(i, j),均满足 s[i][j]=s[j][i]s[i][j] = s[j][i] 的正方形 ss。即第 ii 行第 jj 列处的元素等于第 jj 行第 ii 列处的元素。

你的任务是判断玛莎能否用她所拥有的瓷砖构造出一个大小为 m×mm \times m、且关于主对角线对称的正方形。玛莎可以使用任意数量的每种瓷砖来构造该正方形。注意:她不能旋转瓷砖,只能按输入中给出的方向放置它们。

你需要回答 tt 个相互独立的测试用例。

输入格式

The first line of the input contains one integer tt (1≤t≤1001 \le t \le 100) — the number of test cases. Then tt test cases follow.

The first line of the test case contains two integers nn and mm (1≤n≤1001 \le n \le 100, 1≤m≤1001 \le m \le 100) — the number of types of tiles and the size of the square Masha wants to construct.

The next 2n2n lines of the test case contain descriptions of tiles types. Types of tiles are written one after another, each type is written on two lines.

The first line of the description contains two positive (greater than zero) integers not exceeding 100100 — the number written in the top left corner of the tile and the number written in the top right corner of the tile of the current type. The second line of the description contains two positive (greater than zero) integers not exceeding 100100 — the number written in the bottom left corner of the tile and the number written in the bottom right corner of the tile of the current type.

It is forbidden to rotate tiles, it is only allowed to place them in the orientation they have in the input.

输入的第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤1001 \le n \le 100,1≤m≤1001 \le m \le 100),分别表示瓷砖类型的数量以及玛莎想要构造的正方形的边长。

每个测试用例接下来的 2n2n 行描述了各类瓷砖。瓷砖类型依次给出,每种类型占两行。

每种瓷砖类型的描述中,第一行包含两个正整数(均大于零且不超过 100100)——分别为该类型瓷砖左上角和右上角所写的数字;第二行也包含两个正整数(均大于零且不超过 100100)——分别为该类型瓷砖左下角和右下角所写的数字。

禁止旋转瓷砖,仅允许以输入中给出的方向放置瓷砖。

输出格式

For each test case print the answer: "YES" (without quotes) if Masha can construct the square of size m×mm \times m which is a symmetric matrix. Otherwise, print "NO" (withtout quotes).

对于每个测试用例,输出答案:如果玛莎能够构造一个大小为 m×mm \times m 的对称矩阵,则输出 "YES"(不带引号);否则,输出 "NO"(不带引号)。

输入输出样例

  • 输入#1

    6
    3 4
    1 2
    5 6
    5 7
    7 4
    8 9
    9 8
    2 5
    1 1
    1 1
    2 2
    2 2
    1 100
    10 10
    10 10
    1 2
    4 5
    8 4
    2 2
    1 1
    1 1
    1 2
    3 4
    1 2
    1 1
    1 1

    输出#1

    YES
    NO
    YES
    NO
    YES
    YES

说明/提示

The first test case of the input has three types of tiles, they are shown on the picture below.

Masha can construct, for example, the following square of size 4×44 \times 4 which is a symmetric matrix:

输入的第一个测试用例包含三种类型的方块,如下图所示。

例如,玛莎可以构造如下 4×44 \times 4 的正方形,该正方形是一个对称矩阵:

输入解题思路,AI测评打分。不知道怎么写?

首页