CF1627F.Not Splitting
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a k×k grid, where k is even. The square in row r and column c is denoted by (r,c) . Two squares (r1,c1) and (r2,c2) are considered adjacent if ∣r1−r2∣+∣c1−c2∣=1 .
An array of adjacent pairs of squares is called strong if it is possible to cut the grid along grid lines into two connected, congruent pieces so that each pair is part of the same piece. Two pieces are congruent if one can be matched with the other by translation, rotation, and reflection, or a combination of these.
The picture above represents the first test case. Arrows indicate pairs of squares, and the thick black line represents the cut. You are given an array a of n pairs of adjacent squares. Find the size of the largest strong subsequence of a . An array p is a subsequence of an array q if p can be obtained from q by deletion of several (possibly, zero or all) elements.
输入格式
The input consists of multiple test cases. The first line contains an integer t ( 1≤t≤100 ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two space-separated integers n and k ( 1≤n≤105 ; 2≤k≤500 , k is even) — the length of a and the size of the grid, respectively.
Then n lines follow. The i -th of these lines contains four space-separated integers ri,1 , ci,1 , ri,2 , and ci,2 ( 1≤ri,1,ci,1,ri,2,ci,2≤k ) — the i -th element of a , represented by the row and column of the first square (ri,1,ci,1) and the row and column of the second square (ri,2,ci,2) . These squares are adjacent.
It is guaranteed that the sum of n over all test cases does not exceed 105 , and the sum of k over all test cases does not exceed 500 .
输出格式
For each test case, output a single integer — the size of the largest strong subsequence of a .
输入输出样例
输入#1
3 8 4 1 2 1 3 2 2 2 3 3 2 3 3 4 2 4 3 1 4 2 4 2 1 3 1 2 2 3 2 4 1 4 2 7 2 1 1 1 2 2 1 2 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 1 1 2 2 2 1 6 3 3 3 4
输出#1
7 4 1
说明/提示
In the first test case, the array a is not good, but if we take the subsequence [a1,a2,a3,a4,a5,a6,a8] , then the square can be split as shown in the statement.
In the second test case, we can take the subsequence consisting of the last four elements of a and cut the square with a horizontal line through its center.