codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1598B.md (2751B)


      1 Source: https://codeforces.com/problemset/problem/1598/B
      2 
      3 B. Groups
      4 
      5 time limit per test
      6 
      7 4 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 $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.
     22 
     23 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.
     24 
     25 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.
     26 
     27 Input
     28 
     29 The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases.
     30 
     31 Then the descriptions of $t$ testcases follow.
     32 
     33 The first line of each testcase contains one integer $n$ ($2 \le n \le 1\,000$) — the number of students.
     34 
     35 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.
     36 
     37 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$.
     38 
     39 Output
     40 
     41 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).
     42 
     43 Example
     44 
     45 Input
     46 
     47 ```
     48 2
     49 4
     50 1 0 0 1 0
     51 0 1 0 0 1
     52 0 0 0 1 0
     53 0 1 0 1 0
     54 2
     55 0 0 0 1 0
     56 0 0 0 1 0
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 YES
     63 NO
     64 ```
     65 
     66 Note
     67 
     68 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).
     69 
     70 In the second testcase, it is impossible to divide the students into groups so they attend the lessons on different days.