BitwiseAnd
SRM 596 · 2013-06-25 · by ir5
Problem Statement
For non-negative integers A and B, let A&B denote the bitwise AND operation. That is, for each i, the i-th bit of A&B in binary representation is 1 if and only if the i-th bits of A and B are 1.
We call a set of non-negative integers S cool if the following conditions are satisfied.
- For any two distinct elements A, B in S, A&B > 0.
- For any three distinct elements A, B, C in S, A&B&C = 0.
You are given a
Constraints
- N will be between 3 and 50, inclusive.
- subset will contain between 0 and N elements, inclusive.
- Each element of subset will be between 1 and 2^60 - 1, inclusive.
- All the elements in subset will be distinct.
- Elements in subset will be sorted in increasing order.
{14, 20}
3
Returns: {14, 18, 20 }
There are several possible cool sets. For example, the following sets are cool and each of them contains all the elements of subset. {14, 18, 20} {14, 20, 26} {14, 20, 50} ... Among these sets, the first one is the lexicographically smallest one.
{11, 17, 20}
4
Returns: { }
There is no cool set because (11&20) equals 0.
{99, 157}
4
Returns: {99, 157, 262, 296 }
{1152921504606846975}
3
Returns: { }
The element in subset equals to 2^60-1. Note that each element of your cool set should be less than or equal to 2^60-1.
{}
5
Returns: {15, 113, 402, 676, 840 }
Submissions are judged against all 132 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class BitwiseAnd with a public method vector<long long> lexSmallest(vector<long long> subset, int N) · 132 test cases · 2 s / 256 MB per case