PROBLEM DESCRIPTION

PROBLEM DESCRIPTION
Eg : 1 2
[1] = 1
[2] = 2
[1,2] = 3
PROBLEM DESCRIPTION
Eg : 1 2
[1] = 1
[2] = 2
[1,2] = 3
1,2,3 .... all are distinct.
Observations from the problem..!!
LOGIC FOR OR
| 0 | 0 | 0 |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Observations from the problem..!!
The first observation of the problem is we will have to see the change in number!!
Observations from the problem..!!
The first observation of the problem is we will have to see the change in number!!
So when will the change occur??
Observations from the problem..!!
The first observation of the problem is we will have to see the change in number!!
So when will the change occur??
The answer is if we change a position with bit 0.
Observations from the problem..!!
0 1 1 1 1 1
Number 1 :
Number 2 :
0 1 0 1 0 1
0 1 1 1 1 1
Observations from the problem..!!
0 1 1 1 1 1
Number 1 :
Number 2 :
1 0 0 0 0 0
1 1 1 1 1 1
Approach
1. Sort the array in non incresing order.
2. Calculate the cummulative OR and check if the value is present in unordered set ,
otherwise
insert in the set.
Approach
1 0 0 0
0 1 1 0
0 1 0 1
8 =
6 =
5 =
Approach
1 0 0 0
0 1 1 0
0 1 0 1
8 =
6 =
5 =
1 1 1 0
Approach
1 0 0 0
0 1 1 0
0 1 0 1
8 =
6 =
5 =
1 1 1 0
1 1 1 1
Approach
Why sorting in dec. order?
Approach
Why sorting in dec. order?
To get the value of 1 which is at maximum left.
Approach
Why sorting in dec. order?
1 2 7
Approach
Why sorting in dec. order?
1 2 7
0 1
1 0
1 1 1
Approach
Why sorting in dec. order?
1 2 7
0 1
1 0
1 1 1
0 1 1
CODE
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
long long int* arr = new long long int[n];
for(int i = 0; i<n; i++)
cin >> arr[i];
sort(arr, arr + n);
reverse(arr, arr + n);
unordered_set<long long int> s;
long long int pro = 0;
int c = 0;
for(int i = 0; i<n; i++)
{
pro = pro | arr[i];
if(s.count(pro) > 0)
{
c = 1;
break;
}
s.insert(pro);
}
if(c == 1)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}Still, Have any Doubts???
Still, Have any Doubts???
Comment it You will get a reply
OR
Send your doubt to email provided in description.
Copy of Codechef Cook off
By Chirayu Jain
Copy of Codechef Cook off
- 69