QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 256 MB 満点: 100

#11816. 重排

統計

在一个大小为 $2 \times n$ 的二维整数数组中,是否可以重新排列这些整数,使得任意两个相邻元素(在同一行或同一列中相邻)的和都不能被 3 整除?

输入格式

输入包含多个测试用例。第一行包含一个整数 $t$ ($1 \le t \le 200$),表示测试用例的数量。

对于每个测试用例,第一行包含一个整数 $n$ ($1 \le n \le 10000$),表示数组的列数。 第二行包含数组第一行的元素,以空格分隔。第三行包含数组第二行的元素,以空格分隔。数组元素均为小于 $1000000$ 的正整数。

输出格式

对于每个测试用例,如果存在满足条件的重排方式,则输出 "YES",否则输出 "NO"。

样例

输入 1

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

输出 1

YES
NO
YES
YES
YES
NO

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.