#P12186. Maximize Decimal Value of Binary Concatenation
Maximize Decimal Value of Binary Concatenation
Maximize Decimal Value of Binary Concatenation
You are given an integer n. Consider the sequence of consecutive integers: 1, 2, 3, …, n. For each integer, convert it to its binary representation (without leading zeros). You are allowed to rearrange these numbers in any order. After rearrangement, concatenate their binary representations in that order to form a new binary string. Your task is to choose an ordering such that the value of the resulting binary number (when interpreted in base 2) is maximized, and then output its decimal representation.
Note: The comparison between any two numbers should be made by comparing the concatenated strings in both orders. In other words, for binary strings A and B corresponding to two numbers, order them so that A+B
is lexicographically larger than B+A
.
inputFormat
The input consists of a single integer n which denotes the number of integers. (1 ≤ n ≤ 100, for example)
outputFormat
Output a single integer: the maximum possible decimal value of the concatenated binary string.
sample
1
1