이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int MAX_N = 40 + 2;
int n;
lint m;
lint c[MAX_N];
void solve_edge() {
if (n != 1) return;
lint ans = 1 + (bool) (c[1] <= m);
cout << ans << '\n';
}
int size1, size2;
vector<lint> ord_costs;
void precomp() {
size1 = n / 2;
size2 = n - n / 2;
for (int mask = 0; mask < (1 << size2); mask++) {
lint cost = 0;
for (int b = 0; b < size2; b++) {
if (!(mask & (1 << b))) continue;
cost += c[n / 2 + 1 + b];
}
ord_costs.push_back(cost);
}
sort(ord_costs.begin(), ord_costs.end());
}
int main() {
// freopen("ice.in", "r", stdin);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> c[i];
solve_edge();
precomp();
lint ans = 0;
for (int mask = 0; mask < (1 << size1); mask++) {
lint cost = 0;
for (int b = 0; b < size1; b++) {
if (!(mask & (1 << b))) continue;
cost += c[1 + b];
}
lint tar_cost = m - cost;
lint tar_ind = upper_bound(ord_costs.begin(), ord_costs.end(), tar_cost) - ord_costs.begin();
ans += tar_ind;
}
cout << ans << '\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... |