Submission #362384

#TimeUsernameProblemLanguageResultExecution timeMemory
362384shahriarkhanIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
405 ms20936 KiB
#include<bits/stdc++.h>
using namespace std ;

const int mx = 45 ;

int n , fs , ss ;

long long m , ans = 0 , a[mx] ;

vector<long long> vf , vs ;

int main()
{
    scanf("%d%lld",&n,&m) ;
    for(int i = 1 ; i <= n ; ++i)
    {
        scanf("%lld",&a[i]) ;
    }
    fs = n/2 , ss = n - fs ;
    for(int i = 0 ; i < (1<<fs) ; ++i)
    {
        long long sum = 0 ;
        for(int j = 0 ; j < fs ; ++j)
        {
            if(i&(1<<j)) sum += a[j+1] ;
        }
        vf.push_back(sum) ;
    }
    for(int i = 0 ; i < (1<<ss) ; ++i)
    {
        long long sum = 0 ;
        for(int j = 0 ; j < ss ; ++j)
        {
            if(i&(1<<j)) sum += a[j+fs+1] ;
        }
        vs.push_back(sum) ;
    }
    sort(vf.begin(),vf.end()) ;
    sort(vs.begin(),vs.end()) ;
    for(long long i : vf)
    {
        if(i>m) break ;
        long long cnt = (upper_bound(vs.begin(),vs.end(),m-i) - vs.begin()) ;
        ans += cnt ;
    }
    printf("%lld\n",ans) ;
    return 0 ;
}

Compilation message (stderr)

bobek.cpp: In function 'int main()':
bobek.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |     scanf("%d%lld",&n,&m) ;
      |     ~~~~~^~~~~~~~~~~~~~~~
bobek.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |         scanf("%lld",&a[i]) ;
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...