Codeforces Round #438

来源:互联网 发布:机器小怪升级数据 编辑:程序博客网 时间:2024/06/16 08:13

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 ≤ 1051 ≤ 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 31 0 11 1 01 0 01 0 01 0 0
output
NO
input
3 21 01 10 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个人他们所了不了解。

让你判断是否存在挑出任意几个问题,能让这k个人最多只了解这些问题的一半。

POINT:

答案必为挑2个问题组合,状态压缩一下。


#include <iostream>#include <string.h>#include <stdio.h>#include <map>#include <algorithm>using namespace std;#define LL long longconst int maxn = 20;map<int,int>mp;int main(){    int n,k;    scanf("%d %d",&n,&k);    int cnt[maxn];    int num=0;    for(int i=1;i<=n;i++){        int now=0;        for(int j=0;j<k;j++){            int a;            scanf("%d",&a);            if(a==1)                now=now|(1<<j);        }        if(mp[now]==0){            mp[now]=1;            cnt[++num]=now;        }    }    for(int i=1;i<=num;i++){        for(int j=1;j<=num;j++){            int now=0;            for(int s=0;s<=k;s++){                now=now|((cnt[i]>>s)&(cnt[j]>>s));            }            if(now==0){                printf("YES\n");                return 0;            }        }    }    printf("NO\n");}


原创粉丝点击