编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#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;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:4 ms
内存:268 KiB

输入文件(1.in

5
1 5 -4 3 -1

答案文件(1.out

1

用户输出

1

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:3 ms
内存:248 KiB

输入文件(2.in

6
-1 2 2 5 5 -5

答案文件(2.out

2

用户输出

2

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:3 ms
内存:248 KiB

输入文件(3.in

10
5 -5 5 1 2 3 3 -1 3 1

答案文件(3.out

14

用户输出

14

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:3 ms
内存:248 KiB

输入文件(4.in

1
0

答案文件(4.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:3 ms
内存:248 KiB

输入文件(5.in

4
1 4 -1 0

答案文件(5.out

1

用户输出

1

系统信息

Exited with return code 0
测试点 #6
Accepted
得分:100
用时:2 ms
内存:248 KiB

输入文件(6.in

3
0 0 0

答案文件(6.out

3

用户输出

3

系统信息

Exited with return code 0
测试点 #7
Accepted
得分:100
用时:20 ms
内存:756 KiB

输入文件(7.in

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>

答案文件(7.out

260459

用户输出

260459

系统信息

Exited with return code 0
测试点 #8
Accepted
得分:100
用时:17 ms
内存:744 KiB

输入文件(8.in

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>

答案文件(8.out

81861

用户输出

81861

系统信息

Exited with return code 0
测试点 #9
Accepted
得分:100
用时:5 ms
内存:360 KiB

输入文件(9.in

30
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15

答案文件(9.out

16383

用户输出

16383

系统信息

Exited with return code 0
测试点 #10
Accepted
得分:100
用时:55 ms
内存:928 KiB

输入文件(10.in

34
-480 -519 50 980 136 511 821 -785 471 -781 -452 33 -828 -95 61 939 -372 -942 163 622 447 -48 -46
<51 bytes omitted>

答案文件(10.out

2080461

用户输出

2080461

系统信息

Exited with return code 0