蒟蒻50分求调

P4799 [CEOI2015 Day2] 世界冰球锦标赛

DarkShadow @ 2024-07-12 15:58:26

#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
int n,p;
ll m,d[45],rec[2][1100000],l1,l2,ans;
void dfs(int a,int b,ll c){
    if(a==b+1){
        rec[p][p?++l2:++l1]=c;
        return ;
    }
    dfs(a+1,b,c);
    if(c+d[a]<=m)  dfs(a+1,b,c+d[a]);
}
int main(){
    scanf("%d%lld",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%lld",&d[i]);
    int mid=(1+n)/2;
    dfs(1,mid,0ll);
    p=1;
    dfs(mid+1,n,0ll);
    sort(rec[0]+1,rec[0]+1+l1),sort(rec[1]+1,rec[1]+1+l2);
    rec[1][++l2]=0x7fffffff;
    for(int i=1;i<=l1;i++)
        ans+=(ll)(upper_bound(rec[1]+1,rec[1]+1+l2,m-(ll)(rec[0][i]))-(rec[1]+1));
    printf("%lld",ans);
    return 0;
}

by DarkShadow @ 2024-07-13 11:46:31

AC了,将 upper_bound 改成手写二分


by Ryanwu @ 2025-01-04 11:03:10

全开long long可以过。


|