listings
Problem Author: | Imran AKKI |
Prepared by: | Imran AKKI |
Edited by: | Hasan Saleh (MathModel) |
Solution We know the fact that for any x,y \ge 0 it holds that x \&y \le \min(x,y) because they at the best case share all of the bits.
We want to show that performing the operation sequentially is optimal , because each time the answer will either remain the same or decrease because of definition of AND , i.e. the answer is
Let's simulate the process for n=3
It's obvious that we cannot do more operations on the array and that's the minimum possible value , so the optimal answer is [\underbrace{x,x,...,x}_{n\text{ times}}] which is equivalent to perform the operation infinite number of times.
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
A=a[0]
for i in a:
A&=i
print(A)Complexity .