QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#809321 | #9806. Growing Tree | OIer_kzc# | WA | 2ms | 4096kb | C++20 | 2.0kb | 2024-12-11 14:14:21 | 2024-12-11 14:14:29 |
Judging History
answer
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
#define LOG(FMT...) fprintf(stderr, FMT)
#define fi first
#define se second
#define em emplace
#define eb emplace_back
using namespace std;
typedef long long LL;
constexpr int N = 4096;
int n;
int a[N];
vector<vector<int>> b[N];
bool inter(vector<int> &a, vector<int> &b) {
for (int x : a) {
for (int y : b) {
if (x == y) {
return true;
}
}
}
return false;
int i = 0, j = 0;
while (i < (int)a.size() && j < (int)b.size()) {
if (a[i] == b[j]) {
return true;
}
if (a[i] < b[j]) {
++i;
} else {
++j;
}
}
return false;
}
int merg(vector<vector<int>> &c, vector<vector<int>> &a, vector<vector<int>> &b) {
vector<vector<int>> t;
for (auto &u : a) {
for (auto &v : b) {
if (inter(u, v)) {
continue;
}
t.eb();
for (int x : u) {
t.back().eb(x);
}
for (int y : v) {
t.back().eb(y);
}
/* int i = 0, j = 0;
while (i < (int)u.size() || j < (int)v.size()) {
if (j == (int)v.size() || i < (int)u.size() && u[i] < v[j]) {
t.back().eb(u[i++]);
} else {
t.back().eb(v[j++]);
}
} */
}
}
if (t.size()) {
c = t;
return 0;
}
for (auto &u : a) {
t.eb(u);
}
for (auto &v : b) {
t.eb(v);
}
c = t;
return 1;
}
int solve() {
for (int x = 0; x < (1 << n); ++x) {
b[x].clear();
b[x].eb(vector<int>{0});
}
int sum = 0;
for (int k = 1 << n; k > 1; ) {
for (int x = 0; x < k; ++x) {
int d = a[x + (k - 2)];
for (auto &v : b[x]) {
for (int &t : v) {
t += d;
}
}
}
k >>= 1;
int cnt = 0;
for (int x = 0; x < k; ++x) {
cnt += merg(b[x], b[2 * x], b[2 * x + 1]);
}
if (cnt >= 2) {
return -1;
}
sum += cnt;
}
return sum;
}
int main() {
int task;
for (scanf("%d", &task); task--; ) {
scanf("%d", &n);
for (int i = 0; i < (1 << n + 1) - 2; ++i) {
scanf("%d", a + i);
}
printf("%d\n", solve());
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3732kb
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: 2ms
memory: 4096kb
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 3 0 0 0 1 2 1 0 2 0 1 0 -1 0 -1 0 0 -1 -1 -1 -1 -1 4 -1 0 3 2 -1 -1 -1 -1 1 2 -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 3 -1
result:
wrong answer 1st numbers differ - expected: '2', found: '-1'