forked from codeaholic-shub/ALGO-ADDICT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroups.cpp
More file actions
38 lines (35 loc) · 723 Bytes
/
Groups.cpp
File metadata and controls
38 lines (35 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int arr[n][5];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 5; j++) {
cin >> arr[i][j];
}
}
bool found = false;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
int d1 = 0, d2 = 0, d3 = 0;
for (int k = 0; k < n; k++) {
if (arr[k][i] && arr[k][j])
d3++;
else if (arr[k][i])
d1++;
else if (arr[k][j])
d2++;
}
if (d1 + d2 + d3 == n && d1 <= n / 2 && d2 <= n / 2) {
found = true;
}
}
}
cout << (found ? "YES" : "NO") << "\n";
}
}