Codeforces Round #438 C - Qualification Rounds 思维

时间:2024-01-07 17:01:56
C. Qualification Rounds
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of nproblems, and they want to select any non-empty subset of it as a problemset.

k experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems.

Determine if Snark and Philip can make an interesting problemset!

Input

The first line contains two integers nk (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams.

Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise.

Output

Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.

You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").

Examples
input
5 3
1 0 1
1 1 0
1 0 0
1 0 0
1 0 0
output
NO
input
3 2
1 0
1 1
0 1
output
YES
Note

In the first example you can't make any interesting problemset, because the first team knows all problems.

In the second example you can choose the first and the third problems.

题意:现在有k支队伍要参加一个比赛,题库中有n道题目,其中有些队伍已经知道了某些题目,现在给出每道题目每支队伍是否知道的情况,问是否存在一套题目使得所有队伍最多只知道一半的题目。

思路:若有解,则至少有两套题目满足条件,我们只需找到两套题对所有人均满足条件即可。将每套题的状态,用二进制位保存成数字,当两个数字与运算为0则满足条件。

代码:

 #include<bits/stdc++.h>
#define db double
#define ll long long
#define vec vector<ll>
#define Mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define rep(i, x, y) for(int i=x;i<=y;i++)
const int N = 1e6 + ;
const int mod = 1e9 + ;
const int MOD = mod - ;
const db eps = 1e-;
const db PI = acos(-1.0);
using namespace std; int n,k;
int ans=;
int s[];
bool v[];
int main()
{
cin>>n>>k;
for(int i=;i<n;i++)
{
int ans=;
for(int j=;j<k;j++){
int x;ci(x);
ans+=(<<j)*x;//二进制保存
}
v[ans]=;
}
for(int i=;i<;i++){
for(int j=;j<;j++){
if(v[i]&&v[j]&&!(i&j)) return *puts("YES");//存在与运算为0的情况
}
}
puts("NO");
}