A9006 | Ilya and Matrix
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve.
He's got a square $2^{n}×2^{n}$ -sized matrix and $4^{n}$ integers. You need to arrange all these numbers in the matrix (put each number in a single individual cell) so that the beauty of the resulting matrix with numbers is maximum.
The beauty of a $2^{n}×2^{n}$ -sized matrix is an integer, obtained by the following algorithm:
1. Find the maximum element in the matrix. Let's denote it as $m$ .
2. If $n=0$ , then the beauty of the matrix equals $m$ . Otherwise, a matrix can be split into 4 non-intersecting $2^{n-1}×2^{n-1}$ -sized submatrices, then the beauty of the matrix equals the sum of number $m$ and other four beauties of the described submatrices.
As you can see, the algorithm is recursive.
Help Ilya, solve the problem and print the resulting maximum beauty of the matrix.
He's got a square $2^{n}×2^{n}$ -sized matrix and $4^{n}$ integers. You need to arrange all these numbers in the matrix (put each number in a single individual cell) so that the beauty of the resulting matrix with numbers is maximum.
The beauty of a $2^{n}×2^{n}$ -sized matrix is an integer, obtained by the following algorithm:
1. Find the maximum element in the matrix. Let's denote it as $m$ .
2. If $n=0$ , then the beauty of the matrix equals $m$ . Otherwise, a matrix can be split into 4 non-intersecting $2^{n-1}×2^{n-1}$ -sized submatrices, then the beauty of the matrix equals the sum of number $m$ and other four beauties of the described submatrices.
As you can see, the algorithm is recursive.
Help Ilya, solve the problem and print the resulting maximum beauty of the matrix.
输入格式
The first line contains integer $4^{n}$ $(1<=4^{n}<=2·10^{6})$ . The next line contains $4^{n}$ integers $a_{i}$ $(1<=a_{i}<=10^{9})$ — the numbers you need to arrange in the $2^{n}×2^{n}$ -sized matrix.
输出格式
On a single line print the maximum value of the beauty of the described matrix.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
输入输出样例
输入 #1
1 13
输出 #1
13
输入 #2
4 1 2 3 4
输出 #2
14
Consider the second sample. You need to arrange the numbers in the matrix as follows:
<br></br>1 2<br></br>3 4<br></br>Then the beauty of the matrix will equal: 4 + 1 + 2 + 3 + 4 = 14.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted