CF1627F.Not Splitting

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

There is a k×kk \times k grid, where kk is even. The square in row rr and column cc is denoted by (r,c)(r,c). Two squares (r1,c1)(r_1, c_1) and (r2,c2)(r_2, c_2) are considered adjacent if ∣r1−r2∣+∣c1−c2∣=1\lvert r_1 - r_2 \rvert + \lvert c_1 - c_2 \rvert = 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 aa of nn pairs of adjacent squares. Find the size of the largest strong subsequence of aa. An array pp is a subsequence of an array qq if pp can be obtained from qq by deletion of several (possibly, zero or all) elements.

有一个 k×kk \times k 的网格,其中 kk 为偶数。第 rr 行第 cc 列的方格记作 (r,c)(r,c)。若两个方格 (r1,c1)(r_1, c_1) 和 (r2,c2)(r_2, c_2) 满足 ∣r1−r2∣+∣c1−c2∣=1\lvert r_1 - r_2 \rvert + \lvert c_1 - c_2 \rvert = 1,则称它们相邻。

一个由相邻方格对组成的数组称为强数组(strong),如果可以沿着网格线将整个网格切割成两个**连通的、全等的**部分,使得该数组中的每一对方格都落在同一部分中。两个部分称为全等,是指其中一个可通过平移、旋转、反射或其组合与另一个完全重合。

上图表示第一个测试用例。箭头表示方格对,粗黑线表示切割线。

给定一个包含 nn 个相邻方格对的数组 aa,求 aa 的最长强子序列的长度。数组 pp 是数组 qq 的子序列,当且仅当 pp 可通过从 qq 中删除若干(可能为零个或全部)元素得到。

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤1001 \leq t \leq 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 nn and kk (1≤n≤1051 \leq n \leq 10^5; 2≤k≤5002 \leq k \leq 500, kk is even) — the length of aa and the size of the grid, respectively.

Then nn lines follow. The ii-th of these lines contains four space-separated integers ri,1r_{i,1}, ci,1c_{i,1}, ri,2r_{i,2}, and ci,2c_{i,2} (1≤ri,1,ci,1,ri,2,ci,2≤k1 \leq r_{i,1}, c_{i,1}, r_{i,2}, c_{i,2} \leq k) — the ii-th element of aa, represented by the row and column of the first square (ri,1,ci,1)(r_{i,1}, c_{i,1}) and the row and column of the second square (ri,2,ci,2)(r_{i,2}, c_{i,2}). These squares are adjacent.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5, and the sum of kk over all test cases does not exceed 500500.

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

每个测试用例的第一行包含两个以空格分隔的整数 nn 和 kk(1≤n≤1051 \leq n \leq 10^5;2≤k≤5002 \leq k \leq 500,且 kk 为偶数),分别表示序列 aa 的长度和网格的大小。

接下来是 nn 行。其中第 ii 行包含四个以空格分隔的整数 ri,1r_{i,1}、ci,1c_{i,1}、ri,2r_{i,2} 和 ci,2c_{i,2}(1≤ri,1,ci,1,ri,2,ci,2≤k1 \leq r_{i,1}, c_{i,1}, r_{i,2}, c_{i,2} \leq k),表示序列 aa 的第 ii 个元素,它由第一个方格的行号与列号 (ri,1,ci,1)(r_{i,1}, c_{i,1}) 以及第二个方格的行号与列号 (ri,2,ci,2)(r_{i,2}, c_{i,2}) 给出。这两个方格彼此相邻。

保证所有测试用例中 nn 的总和不超过 10510^5,且所有测试用例中 kk 的总和不超过 500500。

输出格式

For each test case, output a single integer — the size of the largest strong subsequence of aa.

对于每个测试用例,输出一个整数——数组 aa 的最长强子序列的长度。

输入输出样例

  • 输入#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 aa is not good, but if we take the subsequence [a1,a2,a3,a4,a5,a6,a8][a_1, a_2, a_3, a_4, a_5, a_6, a_8], 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 aa and cut the square with a horizontal line through its center.

在第一个测试用例中,数组 aa 不是“好”的,但如果我们取子序列 [a1,a2,a3,a4,a5,a6,a8][a_1, a_2, a_3, a_4, a_5, a_6, a_8],则正方形可以按题目描述所示方式分割。

在第二个测试用例中,我们可以取数组 aa 的最后四个元素构成子序列,并通过正方形中心作一条水平直线将其切割。

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

首页