用户输出
1
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#47377 | #1086. jwp的幸运集合 | Accepted | 100 | 134 ms | 884 K | C++ 11 / 1.3 K | 计算机82赵启 | 2021-03-29 19:46:12 |
#include <stdio.h>
#include <string.h>
#include <map>
#define llu long long
using namespace std;
int n;
int a[36] = { 0 }, *p = a, ans = 0;
map<llu, int> mp1;
map<llu, int> mp2;
int main() {
int i, ban, nn;
scanf("%d", &n);
ban = n >> 1;
nn = n - ban;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int mask = 0, tot = 1 << ban; mask < tot; mask++) {
llu sum = 0, t = 0;
for (int i = 0; i < ban; i++) {
if ((mask >> i) & 1) {
sum += a[i];
t++;
}
}
if (t & 1) {
if (mp1.find(sum) != mp1.end())
mp1[sum]++;
else if (mp1.find(sum) == mp1.end())
mp1[sum] = 1;
} else if (!(t & 1) && t != 0) {
if (sum == 0 && t != 0) {
ans++;
}
if (mp2.find(sum) != mp2.end())
mp2[sum]++;
else if (mp2.find(sum) == mp2.end())
mp2[sum] = 1;
}
}
for (int mask = 0, tot = 1 << nn; mask < tot; mask++) {
llu sum = 0, t = 0;
for (int i = ban; i < n; i++) {
if ((mask >> (i - ban)) & 1) {
sum += -a[i];
t++;
}
}
if (t & 1) {
if (mp1.find(sum) != mp1.end())
ans += mp1[sum];
} else if (!(t & 1) && t != 0) {
if (sum == 0 && t != 0) {
ans++;
}
if (mp2.find(sum) != mp2.end())
ans += mp2[sum];
}
}
printf("%d", ans);
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