用户输出
1
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#49680 | #1086. jwp的幸运集合 | Accepted | 100 | 115 ms | 928 K | C++ 11 / 1.0 K | 丸山彩 | 2021-07-05 17:37:32 |
#include "bits/stdc++.h"
#define pb push_back
#define ls (i << 1)
#define rs ((i << 1) + 1)
using namespace std;
typedef long long ll;
vector<ll> a, b;
map<ll, int> mp[2];
ll ans = 0;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
ll x;
cin >> x;
if (i <= n / 2)
a.pb(x);
else
b.pb(x);
}
int l1 = (1 << ((int)a.size())), l2 = (1 << ((int)b.size()));
// cout << l1 << endl;
for (int i = 0; i < l1; i++) {
ll sum = 0;
for (int j = 0; (i >> j) > 0; j++) {
sum = sum + ((i >> j) & 1) * a[j];
}
// printf("%lld\n", sum);
mp[(__builtin_popcount(i) & 1)][sum]++;
}
for (int i = 0; i < l2; i++) {
ll sum = 0;
for (int j = 0; (i >> j) > 0; j++) {
sum = sum + ((i >> j) & 1) * b[j];
}
if (mp[(__builtin_popcount(i) & 1)].find(-sum) != mp[(__builtin_popcount(i) & 1)].end())
ans = ans + mp[(__builtin_popcount(i) & 1)][-sum];
}
cout << ans - 1;
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