Submission #473314

# Submission time Handle Problem Language Result Execution time Memory
473314 2021-09-15T12:01:00 Z Ahmed57 San (COCI17_san) C++14
48 / 120
95 ms 17428 KB
#include<bits/stdc++.h>
using namespace std;
long long n,k;
vector<pair<long long,long long>> arr(42);
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>k;
    for(int i = 0;i<n;i++){
        long long a,b;cin>>a>>b;
        arr[i] = {a,b};
    }
    arr[40]={0,0};
    long long ans = 0;
    if(n<=20){
        for(long long mask=0;mask<(1<<n);mask++){
            long long s=0,p=40;
            for(long long i=0;i<n;i++){
                if((1<<i)&mask){
                    if(arr[i].first>=arr[p].first){
                        s+=arr[i].second;
                    }
                    else{
                        s=-1;
                        break;
                    }
                    p=i;
                }
            }
            if(s>=k)ans++;
        }
    }else{
        vector<long long> v;
        for(long long mask=0;mask<(1<<20);mask++){
            long long s=0,p=40;
            for(long long i=0;i<20;i++){
                if((1<<i)&mask){
                    if(arr[i].first>=arr[p].first){
                        s+=arr[i].second;
                    }
                    else{
                        s=-1;
                        break;
                    }
                    p=i;
                }
            }
            v.push_back(s);
        }
        n-=20;
        vector<pair<long long,long long>> cd;
        for(int i = 20;i<n;i++){
            cd.push_back({arr[i].first,arr[i].second});
        }
        for(long long mask=0;mask<(1<<n);mask++){
            long long s=0,p=40;
            for(long long i=0;i<n;i++){
                if((1<<i)&mask){
                    if(cd[i].first>=cd[p].first){
                        s+=cd[i].second;
                    }
                    else{
                        s=-1;
                        break;
                    }
                    p=i;
                }
            }
            int y = lower_bound(v.begin(),v.end(),k-s)-v.begin();
            if(y>0&&v[y-1]==k-s)y--;
            ans+=(v.size()-1)-y;
        }
    }
    cout<<ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 204 KB Output is correct
2 Correct 16 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 94 ms 17332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 61 ms 17428 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 95 ms 17348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -