Submission #1368215


Source Code Expand

#include <iostream>
#include <vector>
#include <map>
using namespace std;

#define rep(i, x) for (int i = 0; i < (x); i++)

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> w(N);
    rep (i, N) {
        cin >> w[i];
    }

    int N1 = (N + 1) / 2,
        N2 = N - N1;
    map<int, int> counter;
    rep (mask, 1 << N1) {
        int sum = 0;
        rep (j, N1) {
            if ((mask >> j) & 1) {
                sum += w[j];
            }
        }
        counter[sum]++;
    }

    int ans = 0;
    rep (mask, 1 << N2) {
        int sum = 0;
        rep (j, N2) {
            if ((mask >> j) & 1) {
                sum += w[N1 + j];
            }
        }
        ans += counter[X - sum];
    }
    cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task C - 無駄なものが嫌いな人
User myusa
Language C++14 (GCC 5.4.1)
Score 100
Code Size 801 Byte
Status AC
Exec Time 43 ms
Memory 6400 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 28
Set Name Test Cases
All max_1.txt, max_2.txt, max_3.txt, max_4.txt, pair_1.txt, pair_2.txt, power2_1.txt, power2_2.txt, power2_3.txt, power2_4.txt, power2_5.txt, random_1.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, sample_1.txt, sample_2.txt, sample_3.txt, sample_4.txt, small_1.txt, small_2.txt, small_3.txt, small_4.txt
Case Name Status Exec Time Memory
max_1.txt AC 8 ms 256 KB
max_2.txt AC 12 ms 256 KB
max_3.txt AC 9 ms 256 KB
max_4.txt AC 11 ms 256 KB
pair_1.txt AC 28 ms 2560 KB
pair_2.txt AC 12 ms 256 KB
power2_1.txt AC 18 ms 1792 KB
power2_2.txt AC 13 ms 384 KB
power2_3.txt AC 11 ms 256 KB
power2_4.txt AC 10 ms 256 KB
power2_5.txt AC 3 ms 768 KB
random_1.txt AC 32 ms 4864 KB
random_2.txt AC 33 ms 4864 KB
random_3.txt AC 42 ms 6400 KB
random_4.txt AC 43 ms 6144 KB
random_5.txt AC 13 ms 256 KB
random_6.txt AC 10 ms 256 KB
random_7.txt AC 14 ms 384 KB
random_8.txt AC 25 ms 1792 KB
random_9.txt AC 29 ms 4864 KB
sample_1.txt AC 1 ms 256 KB
sample_2.txt AC 1 ms 256 KB
sample_3.txt AC 2 ms 384 KB
sample_4.txt AC 1 ms 256 KB
small_1.txt AC 1 ms 256 KB
small_2.txt AC 1 ms 256 KB
small_3.txt AC 1 ms 256 KB
small_4.txt AC 1 ms 256 KB