QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#790861 | #9806. Growing Tree | guodong# | WA | 0ms | 3784kb | C++17 | 1.5kb | 2024-11-28 15:44:40 | 2024-11-28 15:44:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> t;
vector<int> a;
int tot[13],ans = 0;
#define ls (pos << 1)
#define rs ((ls) | 1)
#define mid ((l + r) >> 1)
void update(int pos,int l,int r,int dep){
if(l == r){
t[pos].emplace_back(a[pos]);
return;
}
update(ls,l,mid,dep + 1);
update(rs,mid + 1,r,dep + 1);
for(auto &x : t[ls]){
t[pos].emplace_back(x + a[pos]);
}
for(auto &x : t[rs]){
t[pos].emplace_back(x + a[pos]);
}
int fee = t[pos].size();
sort(t[pos].begin(),t[pos].end());
t[pos].resize(unique(t[pos].begin(),t[pos].end()) - t[pos].begin());
fee = fee - t[pos].size();
tot[dep] += fee;
ans += fee;
}
signed main()
{
#ifdef NICEGUODONG
freopen("data.in","r",stdin);
#endif
int T;
cin >> T;
while(T--){
int n;
cin >> n;
for(int i = 0; i < 13; ++i){
tot[i] = 0;
}
ans = 0;
a.clear();
t.clear();
a.resize(1 << (n + 1),0);
t.resize(1 << (n + 3),vector<int>(0));
for(int i = 2; i <= (1 << (n + 1)) - 1; ++i)
cin >> a[i];
update(1,1,1 << n,0);
int flag = 0;
for(int i = 1; i <= n; ++i){
if(tot[i] > 1){
flag = 1;
break;
}
tot[i] += tot[i - 1];
}
if(flag)
cout << -1 << '\n';
else
cout << ans << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
input:
3 2 1 2 4 3 2 1 2 1 2 3 3 2 1 2 1 2 3 3 1 1
output:
1 2 -1
result:
ok 3 number(s): "1 2 -1"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3784kb
input:
94 5 44 65 38 61 64 94 71 53 65 10 24 36 98 74 11 4 5 46 72 34 9 24 37 32 76 29 48 88 17 14 36 4 22 6 71 53 24 61 89 79 39 57 99 61 27 85 99 46 81 75 90 25 16 13 1 87 55 81 56 78 67 2 3 83 3 74 14 45 17 22 41 62 74 25 1 56 22 7 21 73 83 99 3 91 16 53 8 10 49 29 54 81 45 10 12 68 32 9 30 11 99 85 73 ...
output:
-1 0 -1 -1 0 1 -1 0 0 7 0 0 0 1 4 1 0 2 0 2 0 -1 0 -1 0 0 -1 -1 -1 -1 -1 -1 -1 0 -1 3 -1 -1 -1 -1 2 -1 -1 0 0 -1 -1 1 -1 0 -1 2 -1 0 0 0 -1 1 -1 -1 0 0 1 1 -1 0 1 2 0 -1 0 0 1 1 -1 0 -1 0 0 0 -1 -1 -1 1 -1 0 0 0 0 1 0 -1 9 -1
result:
wrong answer 1st numbers differ - expected: '2', found: '-1'