A14599 | Groups
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
$n$ students attended the first meeting of the Berland SU programming course ( $n$ 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.
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.
输入格式
The first line contains a single integer $t$ ( $1 \le t \le 10^4$ ) — the number of testcases.
Then the descriptions of $t$ testcases follow.
The first line of each testcase contains one integer $n$ ( $2 \le n \le 1\,000$ ) — the number of students.
The $i$ -th of the next $n$ lines contains $5$ integers, each of them is $0$ or $1$ . If the $j$ -th integer is $1$ , then the $i$ -th student can attend the lessons on the $j$ -th day of the week. If the $j$ -th integer is $0$ , then the $i$ -th student cannot attend the lessons on the $j$ -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 $10^5$ .
Then the descriptions of $t$ testcases follow.
The first line of each testcase contains one integer $n$ ( $2 \le n \le 1\,000$ ) — the number of students.
The $i$ -th of the next $n$ lines contains $5$ integers, each of them is $0$ or $1$ . If the $j$ -th integer is $1$ , then the $i$ -th student can attend the lessons on the $j$ -th day of the week. If the $j$ -th integer is $0$ , then the $i$ -th student cannot attend the lessons on the $j$ -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 $10^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).
输入输出样例
输入 #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.
In the second testcase, it is impossible to divide the students into groups so they attend the lessons on different days.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted