QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#814148#9806. Growing Treehei_yu_baiWA 18ms7584kbC++201.4kb2024-12-14 15:35:262024-12-14 15:35:28

Judging History

你现在查看的是最新测评结果

  • [2024-12-14 15:35:28]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:7584kb
  • [2024-12-14 15:35:26]
  • 提交

answer

#include<iostream>
using namespace std;
#include<vector>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<unordered_map>

using i64 = long long;

void solve() {
	int n = 0;
	cin >> n;

	vector<i64> a((1 << (n + 1)));
	for (int i = 2; i < (1 << (n + 1)); ++i) {
		cin >> a[i];
		a[i] += a[i >> 1];
	}
	
	vector<i64> b(1 << n), p(1 << n);
	for (int i = 0; i < (1 << n); ++i) {
		b[i] = a[(1 << n) + i];
		p[i] = b[i];
	}

	sort(p.begin(), p.end());
	p.erase(unique(p.begin(), p.end()), p.end());

	unordered_map<i64, int> mp;
	for (int i = 0; i < p.size(); ++i) mp[p[i]] = i + 1;
	for (int i = 0; i < (1 << n); ++i) b[i] = mp[b[i]];

	int tot = p.size();
	int sum = 0;

	int N = 1e6;
	vector<int> num(N);

	for (int i = 1; i <= n; ++i) {
		int d = 1 << i;
		for (int j = 0; j < (1 << n); j += d) {
			for (int k = j; k < j + (d >> 1); ++k) {
				num[b[k]]++;
			}
			bool ok = false;
			for (int k = j + (d >> 1); k < j + d; ++k) {
				if (num[b[k]] > 0) {
					ok = true;
					break;
				}
			}
			if (ok) ++sum;
			for (int k = j; k < j + (d >> 1); ++k) {
				num[b[k]]--;
				if (ok) b[k] = ++tot;
			}
		}
		if (sum > i) {
			cout << "-1\n";
			return;
		}
	}

	cout << sum << "\n";
	return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int t = 1;
	cin >> t;
	while (t--) solve();

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 7456kb

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: 18ms
memory: 7584kb

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:

3
0
-1
2
0
1
-1
0
0
4
0
0
0
1
2
1
0
2
0
2
0
-1
0
-1
0
0
-1
-1
-1
-1
-1
4
-1
0
4
2
7
-1
-1
-1
1
2
5
0
0
3
-1
1
7
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
3
-1
1
-1
0
0
0
0
1
0
-1
4
3

result:

wrong answer 1st numbers differ - expected: '2', found: '3'