Submission #1516393


Source Code Expand

#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int n,x,w[32],m;
vector<int> sum;
void getsum(int i,int s){
    if(i == n){
        sum.pb(s);
        return;
    }

    getsum(i + 1,s);getsum(i + 1,s + w[i]);
}

int c = 0;

void cou(int i,int s){
    if(i == m){
        vector<int>::iterator it = lower_bound(sum.begin(),sum.end(),s);
        while(it != sum.end() && *it == s){
            it++;c++;
        }
        return;
    }
    cou(i + 1,s);cou(i + 1,s - w[i]);
}
int main(){
    scanf("%d%d",&n,&x);
    REP(i,n)
        scanf("%d",w + i);
    m = n / 2;
    getsum(m,0);
    sort(sum.begin(),sum.end());

    cou(0,x);
    printf("%d\n",c);
    return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:40:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&x);
                        ^
./Main.cpp:42:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",w + i);
                          ^

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 395 ms 764 KB
max_2.txt AC 13 ms 640 KB
max_3.txt AC 152 ms 640 KB
max_4.txt AC 29 ms 640 KB
pair_1.txt AC 12 ms 640 KB
pair_2.txt AC 18 ms 640 KB
power2_1.txt AC 6 ms 640 KB
power2_2.txt AC 6 ms 640 KB
power2_3.txt AC 28 ms 640 KB
power2_4.txt AC 63 ms 640 KB
power2_5.txt AC 2 ms 256 KB
random_1.txt AC 8 ms 640 KB
random_2.txt AC 9 ms 640 KB
random_3.txt AC 7 ms 640 KB
random_4.txt AC 12 ms 640 KB
random_5.txt AC 8 ms 640 KB
random_6.txt AC 8 ms 640 KB
random_7.txt AC 13 ms 640 KB
random_8.txt AC 10 ms 640 KB
random_9.txt AC 7 ms 640 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