CF1598B.Groups

入门

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

nn students attended the first meeting of the Berland SU programming course (nn is even). All students will be divided into two groups. Each group will be attending exactly one lesson each week during one of the five working days (Monday, Tuesday, Wednesday, Thursday and Friday), and the days chosen for the groups must be different. Furthermore, both groups should contain the same number of students.

Each student has filled a survey in which they told which days of the week are convenient for them to attend a lesson, and which are not.

Your task is to determine if it is possible to choose two different week days to schedule the lessons for the group (the first group will attend the lesson on the first chosen day, the second group will attend the lesson on the second chosen day), and divide the students into two groups, so the groups have equal sizes, and for each student, the chosen lesson day for their group is convenient.

有 nn 名学生参加了 Berland SU 编程课程的第一次会议(nn 为偶数)。所有学生将被分为两组。每组每周仅在五个工作日(周一、周二、周三、周四、周五)中的一天上课,且两组的上课日期必须不同。此外,两组的学生人数必须相等。

每位学生都填写了一份问卷,说明了自己在一周中哪些日期方便上课,哪些日期不方便。

你的任务是判断:是否存在两个不同的星期几,用于安排两组的课程(第一组在第一个选定的日期上课,第二组在第二个选定的日期上课),并能将学生均分为两组,使得每组人数相等,且对每位学生而言,其所在组的上课日期在其方便的日期之中。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of testcases.

Then the descriptions of tt testcases follow.

The first line of each testcase contains one integer nn (2≤n≤1 0002 \le n \le 1\,000) — the number of students.

The ii-th of the next nn lines contains 55 integers, each of them is 00 or 11. If the jj-th integer is 11, then the ii-th student can attend the lessons on the jj-th day of the week. If the jj-th integer is 00, then the ii-th student cannot attend the lessons on the jj-th day of the week.

Additional constraints on the input: for each student, at least one of the days of the week is convenient, the total number of students over all testcases doesn't exceed 10510^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

接下来是 tt 个测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1 0002 \le n \le 1\,000)—— 学生人数。

接下来的 nn 行中,第 ii 行包含 55 个整数,每个为 00 或 11。若第 jj 个整数为 11,则表示第 ii 个学生能在一周中的第 jj 天上课;若为 00,则表示该学生不能在一周中的第 jj 天上课。

输入的额外约束:对每位学生而言,一周中至少有一天是方便的;所有测试用例的学生总数不超过 10510^5。

输出格式

For each testcase print an answer. If it's possible to divide the students into two groups of equal sizes and choose different days for the groups so each student can attend the lesson in the chosen day of their group, print "YES" (without quotes). Otherwise, print "NO" (without quotes).

对每个测试用例输出一个答案。如果可以将学生分成两个大小相等的组,并为这两个组分别选择不同的日期,使得每个学生都能参加其所在组所选日期的课程,则输出 "YES"(不带引号);否则,输出 "NO"(不带引号)。

输入输出样例

  • 输入#1

    2
    4
    1 0 0 1 0
    0 1 0 0 1
    0 0 0 1 0
    0 1 0 1 0
    2
    0 0 0 1 0
    0 0 0 1 0

    输出#1

    YES
    NO

说明/提示

In the first testcase, there is a way to meet all the constraints. For example, the first group can consist of the first and the third students, they will attend the lessons on Thursday (the fourth day); the second group can consist of the second and the fourth students, and they will attend the lessons on Tuesday (the second day).

In the second testcase, it is impossible to divide the students into groups so they attend the lessons on different days.

在第一个测试用例中,存在一种满足所有约束条件的方案。例如,第一组可以由第一和第三名学生组成,他们将在星期四(第四天)上课;第二组可以由第二和第四名学生组成,他们将在星期二(第二天)上课。

在第二个测试用例中,无法将学生分组,使得各组上课日期互不相同。

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

首页