用户输出
34
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#24204 | #1121. jwp的幸运集合(弱化版) | Accepted | 100 | 29 ms | 384 K | C++ / 1.5 K | 十三月 | 2020-04-16 19:37:32 |
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <sstream>
using namespace std;
struct oj {
int x;
int y;
};
int main() {
map<long long, oj> tong;
long long sum, a, b, c;
int n, ans = 0, m;
cin >> n;
long long *list = new long long[n];
for (long long i = 0; i < n; i++) {
cin >> list[i];
}
a = pow(2, n / 2);
b = pow(2, n / 2 + 1);
for (long long i = 0; i < a; i++) {
sum = 0;
m = 0;
for (long long j = 0; j < n / 2; j++) {
if (i & (1 << j)) {
sum += list[j];
m++;
}
}
if (!tong.count(sum))
tong[sum].x = tong[sum].y = 0;
if (m % 2 == 0)
tong[sum].y++;
tong[sum].x++;
}
c = a;
if (n % 2 != 0)
c = b;
for (long long i = 0; i < c; i++) {
sum = 0;
m = 0;
for (long long j = 0; j < n - n / 2; j++) {
if (i & (1 << j)) {
sum += list[j + n / 2];
m++;
}
}
if (!tong.count(-sum))
tong[-sum].x = 0;
if (m % 2 == 0)
ans += tong[-sum].y;
else
ans += tong[-sum].x - tong[-sum].y;
}
cout << ans - 1;
return 0;
}
用户输出
34
系统信息
Exited with return code 0
用户输出
69
系统信息
Exited with return code 0
20
50000000 -50000000 50000000 -50000000 50000000 -50000000 50000000 -50000000 50000000 -50000000 50
<93 bytes omitted>
用户输出
184755
系统信息
Exited with return code 0
20
50000000 50000000 50000000 50000000 50000000 50000000 50000000 50000000 50000000 50000000 5000000
<82 bytes omitted>
用户输出
0
系统信息
Exited with return code 0
用户输出
255
系统信息
Exited with return code 0