Addition Without Carries
Time limit2sMemory limit512 MB
Given n binary numbers, choose b_i at least a_i so that no two b_i share a 1 bit, minimizing the sum, and print that sum in binary.
- Level
Hard9 of 10
- Topics
- Greedy, Bit manipulation
- Solved
- No attempts yet
Statement
In rare cases, bitwise OR can replace addition of positive integers written in binary. The sum of a set equals its bitwise OR when every bit position has at most one number in the set with a 1 in that position. Call such a set beautiful.
Bitwise OR works like this. The result has a 1 in each bit position where at least one number in the set has a 1.
You are given positive integers . Build a beautiful set of positive integers such that for every from 1 to , and the sum is as small as possible.
Write a program that reads the binary representations of and prints the binary representation of the minimal possible sum of such a beautiful set.
Input
The first line contains the integer , the number of integers in the set (). Each of the next lines contains the binary representation of one positive integer . The numbers have no leading zeros, and the total length of their binary representations does not exceed 300000.
Output
Print the binary representation of the minimal sum of a beautiful set . Print it without leading zeros.