Submission #1515597


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];

map<pair<int,int> ,int> m;

int saiki(int i,int s){
    if(m.find(pair<int,int>(i,s)) != m.end()){
        return m[pair<int,int>(i,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 m[pair<int,int>(i,s)] = saiki(i + 1,s) + saiki(i + 1,s - w[i]);
}

int main(){
    scanf("%d%d",&n,&x);
    REP(i,n)
        scanf("%d",w + i);
    sort(w,w + n,greater<int>());
    printf("%d\n",saiki(0,x));
    return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:38: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:40: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 × 23
TLE × 5
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 1 ms 256 KB
max_2.txt AC 7 ms 1280 KB
max_3.txt AC 1 ms 256 KB
max_4.txt AC 2 ms 384 KB
pair_1.txt TLE 2113 ms 150656 KB
pair_2.txt AC 5 ms 896 KB
power2_1.txt AC 1 ms 256 KB
power2_2.txt AC 1 ms 256 KB
power2_3.txt AC 1 ms 256 KB
power2_4.txt AC 1 ms 256 KB
power2_5.txt AC 1 ms 256 KB
random_1.txt TLE 2115 ms 185344 KB
random_2.txt TLE 2114 ms 167808 KB
random_3.txt AC 126 ms 15744 KB
random_4.txt TLE 2115 ms 181888 KB
random_5.txt AC 3 ms 640 KB
random_6.txt AC 4 ms 768 KB
random_7.txt AC 10 ms 1536 KB
random_8.txt AC 189 ms 19968 KB
random_9.txt TLE 2115 ms 187264 KB
sample_1.txt AC 1 ms 256 KB
sample_2.txt AC 1 ms 256 KB
sample_3.txt AC 3 ms 640 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