Submission #1219628


Source Code Expand

#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

//i番目のビットを返す
bool getBit(int num, int i){
    return ((num & (1 << i)) != 0);
}

//i番目を1にする
int setBit(int num, int i){
    return num | (1 << i);
}

//i番目を0にする
int clearBit(int num, int i){
    int mask = ~(1 << i);
    return num & mask;
}

//i番目をvで置き換える
int updateBit(int num, int i, int v){
    int mask = ~(1 << i);
    return (num & mask) | (v << i);
}

int main(){
    long long n, x;
    cin >> n >> x;

    long long w[33];
    rep(i,n) cin >> w[i];

    long long m = n / 2;
    n-=m;

    vector<long long> a, b;
    rep(i,(1 << n)){
        long long sum = 0;
        rep(j,n){
            if(getBit(i,j)) sum += w[j];
        }
        a.emplace_back(sum);
    }
    rep(i,(1 << m)){
        long long sum = 0;
        rep(j,m){
            if(getBit(i,j)) sum += w[n + j];
        }
        b.emplace_back(sum);
    }

    sort(all(b));
    long long cnt = 0;
    rep(i,a.size()){
        cnt += upper_bound(all(b), x - a[i]) - lower_bound(all(b), x - a[i]);
    }
    cout << cnt << endl;
}

Submission Info

Submission Time
Task C - 無駄なものが嫌いな人
User noy72
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1493 Byte
Status AC
Exec Time 25 ms
Memory 1528 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 14 ms 1528 KB
max_2.txt AC 16 ms 1528 KB
max_3.txt AC 14 ms 1528 KB
max_4.txt AC 16 ms 1528 KB
pair_1.txt AC 25 ms 1528 KB
pair_2.txt AC 21 ms 1528 KB
power2_1.txt AC 16 ms 1528 KB
power2_2.txt AC 15 ms 1528 KB
power2_3.txt AC 16 ms 1528 KB
power2_4.txt AC 15 ms 1528 KB
power2_5.txt AC 2 ms 384 KB
random_1.txt AC 18 ms 1272 KB
random_2.txt AC 18 ms 1272 KB
random_3.txt AC 15 ms 1528 KB
random_4.txt AC 24 ms 1528 KB
random_5.txt AC 18 ms 1528 KB
random_6.txt AC 15 ms 1400 KB
random_7.txt AC 23 ms 1528 KB
random_8.txt AC 20 ms 1528 KB
random_9.txt AC 13 ms 1272 KB
sample_1.txt AC 1 ms 256 KB
sample_2.txt AC 1 ms 256 KB
sample_3.txt AC 1 ms 256 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