Codeforces Round #843 (Div. 2) B. Gardener and the Array
The problem can be solved as follows: for each bit count the number of its occurrences in all numbers in the test. If each number has a bit which occurs in all numbers exactly once, then the answer is “NO”, otherwise the answer is “YES”.
Let’s try to prove this solution. Let there be a number in which all bits occurs in all numbers at least 2 2 2 times. But then it is possible to construct a sequence a a a using all numbers, and a sequence b b b using all numbers except the given one.
If each number has “unique” bits, then all f ( x ) f(x) f(x) will be different.
#include<bits/stdc++.h>
using namespace std;
int main()
{
auto solve=[&](){
map<int,int> b;
int n;cin>>n;
vector<int> a[n];
for(int i=0;i<n;i++)
{
int k;cin>>k;
for(int j=0;j<k;j++)
{
int x;cin>>x;
a[i].push_back(x);
b[x]++;
}
}
for(int i=0;i<n;i++)
{
int ok=1;
for(auto c:a[i])
if(b[c]==1)
{
ok=0;
break;
}
if(ok)
{
cout<<"Yes"<<endl;
return ;
}
}
cout<<"No"<<endl;
};
int T;cin>>T;
while(T--) solve();
return 0;
}