用户输出
34
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#49682 | #1121. jwp的幸运集合(弱化版) | Accepted | 100 | 29 ms | 472 K | C++ 11 / 1.0 K | 丸山彩 | 2021-07-05 17:37:52 |
#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;
}
用户输出
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