CF288C.Polo the Penguin and XOR operation

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to n, inclusive.

For permutation p = _p_0, _p_1, ..., p__n, Polo has defined its beauty — number .

Expression means applying the operation of bitwise excluding "OR" to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is represented as "^" and in Pascal — as "xor".

Help him find among all permutations of integers from 0 to n the permutation with the maximum beauty.

小企鹅 Polo 喜欢排列。但他最喜欢的是从 00 到 nn(含)的所有整数的排列。

对于排列 p=p0, p1, …, pnp = p_0,\,p_1,\,\dots,\,p_n,Polo 定义了它的“美丽值”——即数值
。

表达式 表示对数字 xx 和 yy 执行按位异或(bitwise exclusive OR)运算。该运算存在于所有现代编程语言中;例如,在 C++ 和 Java 中用 ^ 表示,在 Pascal 中用 xor 表示。

请帮助 Polo 在所有从 00 到 nn(含)的整数排列中,找出美丽值最大的那个排列。

输入格式

The single line contains a positive integer n (1 ≤ n ≤ 106).

单行输入包含一个正整数 nn(1≤n≤1061 \leq n \leq 10^6)。

输出格式

In the first line print integer m the maximum possible beauty. In the second line print any permutation of integers from 0 to n with the beauty equal to m.

If there are several suitable permutations, you are allowed to print any of them.

第一行输出整数 mm,表示可能的最大美观度。
第二行输出任意一个由 00 到 nn 的整数组成的排列,使其美观度等于 mm。

若存在多个满足条件的排列,输出其中任意一个即可。

输入输出样例

  • 输入#1

    4

    输出#1

    20
    0 2 1 4 3

输入解题思路,AI测评打分。不知道怎么写?

首页