用户输出
1
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#80793 | #1086. jwp的幸运集合 | Accepted | 100 | 119 ms | 832 K | C++ 17 / 1007 B | 规培005 贺晓珉 | 2022-08-02 14:58:51 |
#include <bits/stdc++.h>
using namespace std;
int n, a[40], arr[2][200001], tot[2];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int len1 = n / 2, len2 = n - n / 2;
long long cnt = 0;
for (int i = 1; i < 1 << len1; i++) {
int m = 0, x = 0;
for (int j = 0; j < len1; j++)
if (i & (1 << j)) {
x += a[j];
m++;
}
arr[m & 1][tot[m & 1]++] = x;
if (x == 0 && (m & 1) == 0)
cnt++;
}
for (int i = 0; i < 2; i++) sort(arr[i], arr[i] + tot[i]);
for (int i = 1; i < 1 << len2; i++) {
int m = 0, x = 0;
for (int j = 0; j < len2; j++)
if (i & (1 << j)) {
x += a[j + len1];
m++;
}
if (x == 0 && (m & 1) == 0)
cnt++;
cnt += upper_bound(arr[m & 1], arr[m & 1] + tot[m & 1], -x) -
lower_bound(arr[m & 1], arr[m & 1] + tot[m & 1], -x);
}
cout << cnt;
return 0;
}
31
749 349 69 -880 282 -926 -831 225 988 552 -193 634 369 476 204 487 387 -803 -370 -975 -17 -485 3
<40 bytes omitted>
用户输出
260459
系统信息
Exited with return code 0
31
362 -14 -181 -465 -400 -232 26 963 70 728 -728 -222 -510 854 139 386 555 994 103 279 213 76 953
<36 bytes omitted>
用户输出
81861
系统信息
Exited with return code 0
用户输出
16383
系统信息
Exited with return code 0