This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
int n,m;
cin >> n >> m;
vector <int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
if (m <= 1000000)
{
vector <int> dp(m+1,0);
dp[0] = 1;
for (int i = 0; i < n; i++)
for (int j = m; j >= a[i]; j--)
dp[j] += dp[j-a[i]];
int cnt = 0;
for (int i = 0; i <= m; i++)
cnt+=dp[i];
cout << cnt << '\n';
}
else
{
int cnt = 0;
for (int i = 0; i < (1<<n); i++)
{
int sum = 0;
for (int j = 0; j < n; j++)
if ((1<<j)&i)
sum+=a[j];
if (sum <= m)
cnt++;
}
cout << cnt << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |