Submission #221903

#TimeUsernameProblemLanguageResultExecution timeMemory
221903MKopchevIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
389 ms8576 KiB
#include<bits/stdc++.h>
using namespace std;
const int nmax=50,MX=(1<<20)+42;

int n;
long long m,inp[nmax];

long long seen[MX];
int pointer=0;

long long output;

void dfs_1(int pos,int target,long long current)
{
    if(current>m)return;

    if(pos>target)
    {
        pointer++;
        seen[pointer]=current;
        return;
    }

    dfs_1(pos+1,target,current);

    dfs_1(pos+1,target,current+inp[pos]);
}

void dfs_2(int pos,int target,long long current)
{
    if(current>m)return;

    if(pos>target)
    {
        int pos=upper_bound(seen+1,seen+pointer+1,m-current)-seen;

        output=output+pos-1;

        return;
    }

    dfs_2(pos+1,target,current);

    dfs_2(pos+1,target,current+inp[pos]);
}

int main()
{
    scanf("%i%lld",&n,&m);

    for(int i=1;i<=n;i++)scanf("%lld",&inp[i]);

    dfs_1(1,n/2,0);

    sort(seen+1,seen+pointer+1);

    dfs_2(n/2+1,n,0);

    printf("%lld\n",output);
    return 0;
}

Compilation message (stderr)

bobek.cpp: In function 'int main()':
bobek.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%lld",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~~
bobek.cpp:51:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++)scanf("%lld",&inp[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...