CF1844E.Great Grids
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
An n×m grid of characters is called great if it satisfies these three conditions:
- Each character is either 'A', 'B', or 'C'.
- Every 2×2 contiguous subgrid contains all three different letters.
- Any two cells that share a common edge contain different letters.
Let (x,y) denote the cell in the x-th row from the top and y-th column from the left.
You want to construct a great grid that satisfies k constraints. Each constraint consists of two cells, (xi,1,yi,1) and (xi,2,yi,2), that share exactly one corner. You want your great grid to have the same letter in cells (xi,1,yi,1) and (xi,2,yi,2).
Determine whether there exists a great grid satisfying all the constraints.
一个 n×m 的字符网格被称为“优秀网格”,当且仅当它满足以下三个条件:
- 每个字符均为
'A'、'B'或'C'之一; - 每个 2×2 的连续子网格都包含全部三种不同的字母;
- 任意两个共享一条公共边的格子中,字符互不相同。
记 (x,y) 表示从上往下第 x 行、从左往右第 y 列的格子。
你需要构造一个满足 k 个约束条件的优秀网格。每个约束条件由两个恰好共享一个顶点(即对角相邻)的格子 (xi,1,yi,1) 和 (xi,2,yi,2) 组成;你要求在这两个格子中填入相同的字母。
判断是否存在一个满足所有约束条件的优秀网格。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤103). The description of the test cases follows.
The first line of each test case contains three integers, n, m, and k (2≤n,m≤2⋅103, 1≤k≤4⋅103).
Each of the next k lines contains four integers, xi,1, yi,1, xi,2, and yi,2 (1≤xi,1<xi,2≤n, 1≤yi,1,yi,2≤m). It is guaranteed that either (xi,2,yi,2)=(xi,1+1,yi,1+1) or (xi,2,yi,2)=(xi,1+1,yi,1−1).
The pairs of cells are pairwise distinct, i.e. for all 1≤i<j≤k, it is not true that xi,1=xj,1, yi,1=yj,1, xi,2=xj,2, and yi,2=yj,2.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅103.
It is guaranteed that the sum of m over all test cases does not exceed 2⋅103.
It is guaranteed that the sum of k over all test cases does not exceed 4⋅103.
每个测试包含多个测试用例。第一行包含测试用例数量 t(1≤t≤103)。随后是各测试用例的描述。
每个测试用例的第一行包含三个整数 n、m 和 k(2≤n,m≤2⋅103,1≤k≤4⋅103)。
接下来的 k 行中,每行包含四个整数 xi,1、yi,1、xi,2 和 yi,2(1≤xi,1<xi,2≤n,1≤yi,1,yi,2≤m)。保证对每个 i,要么 (xi,2,yi,2)=(xi,1+1,yi,1+1),要么 (xi,2,yi,2)=(xi,1+1,yi,1−1)。
这些单元格对两两互异,即对所有 1≤i<j≤k,不同时满足 xi,1=xj,1、yi,1=yj,1、xi,2=xj,2 且 yi,2=yj,2。
保证所有测试用例中 n 的总和不超过 2⋅103。
保证所有测试用例中 m 的总和不超过 2⋅103。
保证所有测试用例中 k 的总和不超过 4⋅103。
输出格式
For each test case, output "YES" if a great grid satisfying all the constraints exists and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
对于每个测试用例,如果存在满足所有约束条件的优秀网格,则输出 “YES”,否则输出 “NO”。
你可以以任意大小写形式输出答案(大写或小写)。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均会被识别为肯定回答。
输入输出样例
输入#1
4 3 4 4 1 1 2 2 2 1 3 2 1 4 2 3 2 3 3 2 2 7 2 1 1 2 2 1 2 2 1 8 5 4 1 2 2 1 1 5 2 4 7 1 8 2 7 4 8 5 8 5 4 1 2 2 1 1 5 2 4 7 1 8 2 7 5 8 4
输出#1
YES NO YES NO
说明/提示
In the first test case, the following great grid satisfies all the constraints:
B
A
B
C
C
B
C
A
A
C
A
B
In the second test case, the two constraints imply that cells (1,1) and (2,2) have the same letter and cells (1,2) and (2,1) have the same letter, which makes it impossible for the only 2×2 subgrid to contain all three different letters.
在第一个测试用例中,以下优秀的网格满足所有约束条件:
B
A
B
C
C
B
C
A
A
C
A
B
在第二个测试用例中,两条约束意味着单元格 (1,1) 与 (2,2) 具有相同的字母,且单元格 (1,2) 与 (2,1) 具有相同的字母,这使得唯一的 2×2 子网格无法包含全部三种不同的字母。
输入解题思路,AI测评打分。不知道怎么写?