用户输出
34
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#22895 | #1121. jwp的幸运集合(弱化版) | Accepted | 100 | 20 ms | 408 K | C++ / 1.8 K | 计试91-李禹陪 | 2020-02-15 14:44:16 |
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false); //关cin同步;加速
int n;
cin >> n;
int c1[10];
int *sum1 = new int[1 << (n / 2)], *cnt1 = new int[1 << (n / 2)];
int result = 0;
for (int i = 0; i < n / 2; i++) cin >> c1[i];
map<int, int> a1, a2;
for (int i = 0; i < (1 << (n / 2)); i++) { //折半枚举二进制的位数,n个数
sum1[i] = 0, cnt1[i] = 0;
for (int j = 0; j < n / 2; j++) {
if (i & (1 << j))
sum1[i] += c1[n / 2 - 1 - j], cnt1[i]++;
}
}
for (int i = 0; i < (1 << (n / 2)); i++) {
if (a1.find(sum1[i]) == a1.end() && cnt1[i] % 2 == 1)
a1[sum1[i]] = 0;
if (a2.find(sum1[i]) == a2.end() && cnt1[i] % 2 == 0)
a2[sum1[i]] = 0;
if (a1.find(sum1[i]) != a1.end() && cnt1[i] % 2 == 1)
a1[sum1[i]]++; //分元素个数的奇偶
if (a2.find(sum1[i]) != a2.end() && cnt1[i] % 2 == 0)
a2[sum1[i]]++;
}
//下面解决下一半
int c2[10];
for (int i = 0; i < n / 2; i++) cin >> c2[i];
if (n % 2 == 1)
cin >> c2[n / 2];
int *sum2 = new int[1 << (n / 2)], *cnt2 = new int[1 << (n / 2)];
for (int i = 0; i < (1 << (n / 2)); i++) {
sum2[i] = 0, cnt2[i] = 0;
for (int j = 0; j < n / 2; j++) {
if (i & (1 << j))
sum2[i] += c2[n / 2 - 1 - j], cnt2[i]++;
}
}
for (int i = 0; i < (1 << (n / 2)); i++) {
if (cnt2[i] % 2 == 1 && a1.find(-sum2[i]) != a1.end())
result += a1[-sum2[i]];
if (cnt2[i] % 2 == 0 && a2.find(-sum2[i]) != a2.end())
result += a2[-sum2[i]];
}
if (n % 2 == 1) {
for (int i = 0; i < (1 << (n / 2)); i++) sum2[i] += c2[n / 2], cnt2[i]++;
for (int i = 0; i < (1 << (n / 2)); i++) {
if (cnt2[i] % 2 == 1 && a1.find(-sum2[i]) != a1.end())
result += a1[-sum2[i]];
if (cnt2[i] % 2 == 0 && a2.find(-sum2[i]) != a2.end())
result += a2[-sum2[i]];
}
}
cout << result - 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