Find a pair in an array with maximum bitwise OR? $$$1 \leq n \leq 1e6, 0 \leq a[i] \leq 1e6$$$
Can anyone help me with the solution or finding a blog somewhere.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Название |
---|
Maybe we can use SOS DP. Idea ->
We apply SOS DP to find array B, where B[i] represents the maximum masked value present in the given array where (value & i) == i.
Now, We again apply SOS to find array C, where C[i] represents the maximum values of B[i] among all the sub mask of C[i]. now to get maximum or with A[i], we complement it and get the corresponding answer from C[~A[i]].
Yuki726 I know the explanation is weird. But look at the code below, it's simple. Let me know if it is failing or if I am wrong somewhere. Code
Same approach has been mentioned in Maxor editorial. So probably your approach is correct (I tested with brute force too). But I am unable to prove it.
Thanks for the reply. Your code is correct and I was finally able to prove it.
Welcome!
nvm
Check this out ...
problem:- https://www.codechef.com/problems/MAXOR
editorial:- https://discuss.codechef.com/t/maxor-ediorial/15798