#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define int long long
const long long inf=1e18;
const int MOD=1e9+7;
const int N=41;
int a[N],n,m,ans=0,dp[40][1000001];
void func(int i,int score){
if(i==n){
ans++;
return;
}
func(i+1,score);
if(score+a[i]<=m)func(i+1,score+a[i]);
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++)cin>>a[i];
if(n<=20)func(0,0);
else{
dp[0][0]=1; dp[0][a[0]]=1;
for(int i=1;i<n;i++){
for(int j=0;j<=m;j++){
if(j>a[i] && dp[i-1][j-a[i]]>0)dp[i][j]=dp[i-1][j-a[i]]+dp[i-1][j];
else dp[i][j]=dp[i-1][j];
if(j==a[i])dp[i][j]++;
}
}
for(int j=0;j<=m;j++){
ans+=dp[n-1][j];
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
72028 KB |
Output is correct |
2 |
Correct |
52 ms |
240284 KB |
Output is correct |
3 |
Correct |
75 ms |
308488 KB |
Output is correct |
4 |
Correct |
49 ms |
232072 KB |
Output is correct |
5 |
Correct |
5 ms |
63836 KB |
Output is correct |
6 |
Correct |
19 ms |
100952 KB |
Output is correct |
7 |
Correct |
31 ms |
185004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
78424 KB |
Output is correct |
2 |
Correct |
22 ms |
129708 KB |
Output is correct |
3 |
Correct |
7 ms |
80476 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
59740 KB |
Output is correct |
6 |
Correct |
60 ms |
244564 KB |
Output is correct |
7 |
Correct |
6 ms |
69980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
209620 KB |
Output is correct |
2 |
Correct |
29 ms |
156240 KB |
Output is correct |
3 |
Correct |
27 ms |
152188 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
74076 KB |
Output is correct |
6 |
Correct |
44 ms |
230088 KB |
Output is correct |
7 |
Correct |
32 ms |
209676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |