用户输出
23
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#103964 | #1432. [L2-1] 树木加固 | Accepted | 100 | 282 ms | 4480 K | C++ 11 / 1.1 K | PotassiumIon | 2024-05-12 17:58:17 |
#include <iostream>
#define _USE_MATH_DEFINES
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <string>
#include <array>
using namespace std;
#define LL long long
const int MAXN = (1 << 20) + 10;
int tree[MAXN];
int n;
// layer = 2..N
// int CalcAndModify(int layer)
// {
// int sum = 0;
// for (auto i = (1<<(layer-1)); i < (1<<layer); i++)
// {
// sum += abs(tree[i]);
// tree[i>>1] += tree[i];
// }
// return sum;
// }
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (auto i = 1; i < (1 << n); i++) {
cin >> tree[i];
}
int sum = 0;
for (auto i = (1 << n) - 1; i > 0; i--) {
sum += abs(tree[i]);
tree[i >> 1] += tree[i];
}
// cout << tree[1] << endl;
cout << sum << endl;
// for(int i=n;i>1;i--)
// {
// for(j=(1<<(i-1));j<(1<<i);j++)
// sum+=abs(tree[j]);
// for(j=(1<<(i-2));j<(1<<(i-1));j++)
// tree[j]=tree[j*2]+tree[j*2+1];
// }
return 0;
}
用户输出
11887
系统信息
Exited with return code 0
用户输出
8158
系统信息
Exited with return code 0
8
114
-808 -998
-826 -984 316 9
-510 -266 401 -830 860 388 -560 -918
67 -319 -972 -451 -30 267 -
<1036 bytes omitted>
用户输出
272319
系统信息
Exited with return code 0
8
-822
-975 757
984 -999 989 -284
81 981 -308 998 -596 395 -673 -738
889 -780 -353 448 -788 -492
<1037 bytes omitted>
用户输出
255014
系统信息
Exited with return code 0
8
-646
-115 -20
-448 712 -920 618
-28 -977 317 160 -621 970 -994 -326
-738 446 -103 -190 218 958
<1037 bytes omitted>
用户输出
273545
系统信息
Exited with return code 0
8
-26
-528 -860
-580 687 -902 680
-997 -939 858 -150 43 977 -605 813
-732 128 28 -68 693 -525 31
<1035 bytes omitted>
用户输出
259605
系统信息
Exited with return code 0
20
53
-291 14
-319 278 -699 -876
-867 947 653 -677 138 359 -47 -702
-112 341 -445 -435 -312 -450
<2176336 bytes omitted>
用户输出
37703792
系统信息
Exited with return code 0
20
-654
-404 -914
-142 819 -993 -963
42 -707 292 -964 -857 408 -33 -731
-877 -2 515 206 877 952
<2176313 bytes omitted>
用户输出
38042269
系统信息
Exited with return code 0