# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
80022 | pzdba | San (COCI17_san) | C++14 | 272 ms | 3116 KiB |
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>
using namespace std;
typedef long long LL;
LL h[45], g[45];
vector<LL> dp[25];
int main(){
int n;
LL k;
scanf("%d%lld", &n, &k);
for(int i=0;i<n;i++){
scanf("%lld%lld", &h[i], &g[i]);
}
if(n == 1){
if(g[1] >= k) printf("1\n");
else printf("0\n");
return 0;
}
int mid1 = n/2;
LL ans = 0;
for(int i=1;i<(1<<mid1);i++){
int mx = 0, last = -1;
LL sum = 0;
bool ok = 1;
for(int j=0;j<mid1;j++){
if((i>>j)&1){
if(h[j] < mx){
ok = 0;
break;
}
mx = h[j];
last = j;
sum += g[j];
}
}
if(!ok) continue;
dp[last].emplace_back(sum);
if(sum >= k) ans++;
}
for(int i=0;i<mid1;i++) sort(dp[i].begin(), dp[i].end());
int mid2 = n - mid1;
for(int i=1;i<(1<<mid2);i++){
int mx = 0, last = -1;
LL sum = 0;
bool ok = 1;
for(int j=0;j<mid2;j++){
if((i>>j)&1){
if(h[j+mid1] < mx){
ok = 0;
break;
}
mx = h[j+mid1];
if(last == -1) last = j+mid1;
sum += g[j+mid1];
}
}
if(!ok) continue;
for(int j=0;j<mid1;j++){
if(h[last] >= h[j]){
int idx = lower_bound(dp[j].begin(), dp[j].end(), k-sum) - dp[j].begin();
ans += dp[j].size() - idx;
}
}
if(sum >= k) ans++;
}
printf("%lld\n", ans);
}
Compilation message (stderr)
# | 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... |