CitadelOA #1
Distinct Goodness Values
Estimated MediumJudge-ready
Topics (AI-labelled)SubsequencesBits & Math
Choose a subsequence of the original array that preserves order and is strictly increasing in value, and compute its bitwise OR; return all distinct results in ascending order. The OR of the empty subsequence is 0. The old curated page for problem 1 mistakenly said it returns a count, and this is now restored according to the original text.
Input
The first line contains n, followed by n integers. 1≤n≤10000, 1≤a[i]<1024. The separate Fastprep page for problem 15, the same problem, together with the OCR supplies its missing ranges.
Output
The first line contains the number of results, and the second line contains the distinct OR values in ascending order, including 0.
Example 1
Input:
4
4 2 4 1
Output:
5
0 1 2 4 6
Example 2
Input:
4
3 2 4 6
Output:
6
0 2 3 4 6 7
Example 3
Input:
4
3 5 5 1
Output:
5
0 1 3 5 7
Example notes
The outputs of the three public examples are, in order: 5 / 0 1 2 4 6; 6 / 0 2 3 4 6 7; 5 / 0 1 3 5 7. These answers were verified by independent enumeration or direct simulation.
Editorial
Loading solution…