编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#100743 #1086. jwp的幸运集合 Accepted 100 123 ms 972 K C++ / 1.1 K XJTUXXX 2023-09-07 21:26:23
显示原始代码
#include <bits/stdc++.h>
#include <map>

using namespace std;
typedef long long ll;
int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int nums[n];
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
    }
    map<int, ll> jmp;
    map<int, ll> omp;
    int mid = n / 2, els = n - mid;
    for (ll mask = 0, toll = 1 << mid; mask < toll; mask++) {
        int count = 0;
        ll sum = 0;
        for (int i = 0; i < mid; i++) {
            if ((mask >> i) & 1) {
                count++;
                sum += nums[i];
            }
        }
        if (count % 2 == 0) {
            omp[sum]++;
        } else {
            jmp[sum]++;
        }
    }
    ll ans = -1;
    for (ll mask = 0, toll = 1 << els; mask < toll; mask++) {
        int count = 0;
        ll sum = 0;
        for (int i = 0; i < els; i++) {
            if ((mask >> i) & 1) {
                count++;
                sum += nums[i + mid];
            }
        }
        if (count % 2 == 0) {
            ans += omp[-sum];
        } else {
            ans += jmp[-sum];
        }
    }
    cout << ans;
    return 0;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:5 ms
内存:248 KiB

输入文件(1.in

5
1 5 -4 3 -1

答案文件(1.out

1

用户输出

1

系统信息

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

输入文件(2.in

6
-1 2 2 5 5 -5

答案文件(2.out

2

用户输出

2

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:5 ms
内存:356 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
用时:6 ms
内存:332 KiB

输入文件(4.in

1
0

答案文件(4.out

0

用户输出

0

系统信息

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

输入文件(5.in

4
1 4 -1 0

答案文件(5.out

1

用户输出

1

系统信息

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

输入文件(6.in

3
0 0 0

答案文件(6.out

3

用户输出

3

系统信息

Exited with return code 0
测试点 #7
Accepted
得分:100
用时:21 ms
内存:896 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
内存:972 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
用时:10 ms
内存:336 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
用时:46 ms
内存:896 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