Submission #1515994


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[40];
 
int saiki(int i,int s){
    if(i == n){
        return s == 0;
    }
    if(s == 0)
        return 1;
    if(s < 0)
        return 0;
    if((n - i) * w[i] < s)
        return 0;
 
    return saiki(i + 1,s) + saiki(i + 1,s - w[i]);
}

int dp[2][20000001];
 
int main(){
    scanf("%d%d",&n,&x);
    REP(i,n)
        scanf("%d",w + i);
    sort(w,w + n,greater<int>());
    int s = 0;
    REP(i,n)
        s += w[i];
    if(s < x){
        printf("0\n");
        return 0;
    }else if(s == x){
        printf("1\n");
        return 0;
    }
    if(n < 27 || x > 20000000){
        printf("%d\n",saiki(0,x));
        return 0;
    }
    REP(i,x + 1)
        dp[1][i] = 0;
    dp[1][0] = 1;

    RREP(i,n){
        REP(j,x + 1){
            dp[0][j] = dp[1][j] + ((j - w[i] >= 0) ? dp[1][j - w[i]] : 0);
        }
        REP(j,x + 1)
            dp[1][j] = dp[0][j];
    }
    printf("%d\n",dp[1][x]);
    return 0;
}

Submission Info

Submission Time
Task C - 無駄なものが嫌いな人
User kyawakyawa
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1436 Byte
Status TLE
Exec Time 2103 ms
Memory 2304 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:35: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:37: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 0 / 100
Status
AC × 20
TLE × 8
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 TLE 2103 ms 256 KB
max_2.txt TLE 2103 ms 256 KB
max_3.txt TLE 2103 ms 256 KB
max_4.txt AC 2 ms 2304 KB
pair_1.txt AC 910 ms 256 KB
pair_2.txt TLE 2103 ms 256 KB
power2_1.txt AC 1 ms 256 KB
power2_2.txt AC 2 ms 2304 KB
power2_3.txt AC 299 ms 256 KB
power2_4.txt AC 2 ms 2304 KB
power2_5.txt AC 1 ms 256 KB
random_1.txt TLE 2103 ms 256 KB
random_2.txt AC 212 ms 256 KB
random_3.txt AC 3 ms 256 KB
random_4.txt TLE 2103 ms 256 KB
random_5.txt AC 2 ms 2304 KB
random_6.txt AC 2 ms 2304 KB
random_7.txt TLE 2103 ms 256 KB
random_8.txt TLE 2103 ms 256 KB
random_9.txt AC 136 ms 256 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