답안 #886716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886716 2023-12-12T17:40:22 Z vjudge1 San (COCI17_san) C++17
48 / 120
671 ms 65536 KB
#ifndef Local
    #pragma GCC optimize("O3,unroll-loops")
    const int lim=1000;
#else
    const int lim=1000;
#endif

#include "bits/stdc++.h"
using namespace std;

#define int int64_t
#define pb push_back

const int mod=1e9+7;
using pii=pair<int,int>;

struct fenwick{
    int n;
    int tree[lim];
    fenwick(int n):n(n){
        memset(tree,0,sizeof(tree));
    }
    void update(int p,int val){
        p++;
        while(p<=n){
            tree[p]+=val;
            p+=p&-p;
        }
    }
    int query(int p){
        p++;
        int res=0;
        while(0<p){
            res+=tree[p];
            p-=p&-p;
        }
        return res;
    }
    int query(int l,int r){
        return query(r)-query(l-1);
    }
};

inline void solve(){
    int n,k;
    cin>>n>>k;
    pii a[n];
    int lens[n];
    for(int i=0;i<n;i++){
        cin>>a[i].first>>a[i].second;
        lens[i]=a[i].first;
    }
    if(n<=20){
        int ans=0;
        for(int m=1;m<(1<<n);m++){
            int past=-1,cur=0;
            for(int i=0;i<n;i++){
                if(!(m&(1<<i)))continue;
                if(!(~past)||a[past].first<=a[i].first){
                    cur+=a[i].second;
                    past=i;
                }else{
                    goto nextt;
                }
            }
            if(k<=cur){
                //cerr<<"passed "<<(bitset<4>(m))<<" "<<cur<<"\n";
                ans++;
                continue;
            }
            nextt:;
            //cerr<<"failed "<<(bitset<4>(m))<<"\n";
        }
        cout<<ans<<"\n";
    }else{
        sort(lens,lens+n);
        unordered_map<int,int>to;
        for(int i=0;i<n;i++){
            to[lens[i]]=i;
        }
        for(int i=0;i<n;i++){
            a[i].first=to[a[i].first];
        }
        map<pii,int>begins,ends;
        for(int m=1;m<(1<<20);m++){
            int past=-1,cur=0;
            for(int i=0;i<20;i++){
                if(!(m&(1<<i)))continue;
                if(!(~past)||a[past].first<=a[i].first){
                    cur+=a[i].second;
                    past=i;
                }else{
                    goto nexttt;
                }
            }
            begins[pii{cur,a[past].first}]++;
            nexttt:;
        }
        for(int m=1;m<(1<<(n-20));m++){
            int first=-1,past=-1,cur=0;
            for(int i=0;i<(n-20);i++){
                if(!(m&(1<<i)))continue;
                if(!(~past)){
                    first=i+20;
                }
                if(!(~past)||a[past].first<=a[i+20].first){
                    cur+=a[i+20].second;
                    past=i+20;
                }else{
                    goto nextttt;
                }
            }
            ends[pii(cur,a[first].first)]++;
            nextttt:;
        }
        fenwick all(500);
        int ans=0;
        auto j=ends.rbegin();
        for(auto [p,c]:begins){
            while(j!=ends.rend()&&k<=j->first.first+p.first){
                //cerr<<"updated"<<j->first.second<<" "<<j->second<<"\n";
                all.update(j->first.second,j->second);
                j++;
            }
            //cerr<<p.first<<" "<<p.second<<" "<<all.query(p.second-1,50)<<"\n";
            ans+=c*all.query(p.second-1,100);
        }
        //cerr<<all.query(0,50)<<"\n";
        cout<<ans<<"\n";
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
#ifdef Local  
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#else
    //freopen("grass.in","r",stdin);
    //freopen("grass.out","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 348 KB Output is correct
2 Correct 11 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 671 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 68 ms 11720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 520 ms 50044 KB Output isn't correct
2 Halted 0 ms 0 KB -