답안 #374225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
374225 2021-03-06T23:41:08 Z MilosMilutinovic Ice Hockey World Championship (CEOI15_bobek) C++14
100 / 100
546 ms 8812 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=45;
ll a[N];
int main(){
    int n;scanf("%i",&n);
    ll m;scanf("%lld",&m);
    for(int i=0;i<n;i++)scanf("%lld",&a[i]);
    int b=n/2;
    vector<ll> all;
    ll ans=1;
    for(int i=1;i<(1<<b);i++){
        ll sum=0LL;
        for(int j=0;j<b;j++){
            if(i&(1<<j))sum+=a[j];
        }
        all.pb(sum);
        if(sum<=m)ans++;
    }
    sort(all.begin(),all.end());
    int sz=n-b;
    /*auto Get=[&](ll x){
        if(x>m)return 0;
        return (int)(lower_bound(all.begin(),all.end(),m-x)-all.begin());
    };*/
    for(int i=1;i<(1<<sz);i++){
        ll sum=0LL;
        for(int j=0;j<sz;j++){
            if(i&(1<<j))sum+=a[b+j];
        }
        int bot=0,top=(int)all.size()-1,pos=0;
        ll need=m-sum;
        while(bot<=top){
            int mid=bot+top>>1;
            if(all[mid]<=need)pos=mid+1,bot=mid+1;
            else top=mid-1;
        }
        ans+=pos;
        if(sum<=m)ans++;
    }
    printf("%lld",ans);
}

Compilation message

bobek.cpp: In function 'int main()':
bobek.cpp:36:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |             int mid=bot+top>>1;
      |                     ~~~^~~~
bobek.cpp:8:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |     int n;scanf("%i",&n);
      |           ~~~~~^~~~~~~~~
bobek.cpp:9:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |     ll m;scanf("%lld",&m);
      |          ~~~~~^~~~~~~~~~~
bobek.cpp:10:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |     for(int i=0;i<n;i++)scanf("%lld",&a[i]);
      |                         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1020 KB Output is correct
2 Correct 104 ms 2528 KB Output is correct
3 Correct 539 ms 8664 KB Output is correct
4 Correct 112 ms 2676 KB Output is correct
5 Correct 17 ms 1000 KB Output is correct
6 Correct 8 ms 772 KB Output is correct
7 Correct 15 ms 1000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 1508 KB Output is correct
2 Correct 35 ms 1000 KB Output is correct
3 Correct 214 ms 4572 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 8 ms 748 KB Output is correct
6 Correct 18 ms 1000 KB Output is correct
7 Correct 18 ms 1000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 1508 KB Output is correct
2 Correct 171 ms 2528 KB Output is correct
3 Correct 162 ms 2528 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 97 ms 2528 KB Output is correct
6 Correct 247 ms 8660 KB Output is correct
7 Correct 96 ms 2528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 366 ms 4572 KB Output is correct
2 Correct 31 ms 1000 KB Output is correct
3 Correct 11 ms 748 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 8 ms 748 KB Output is correct
6 Correct 191 ms 4572 KB Output is correct
7 Correct 15 ms 1008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 1000 KB Output is correct
2 Correct 99 ms 2528 KB Output is correct
3 Correct 9 ms 748 KB Output is correct
4 Correct 12 ms 748 KB Output is correct
5 Correct 122 ms 2528 KB Output is correct
6 Correct 20 ms 1000 KB Output is correct
7 Correct 264 ms 8776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 455 ms 8664 KB Output is correct
2 Correct 35 ms 1000 KB Output is correct
3 Correct 11 ms 748 KB Output is correct
4 Correct 546 ms 8812 KB Output is correct
5 Correct 143 ms 4572 KB Output is correct
6 Correct 15 ms 1000 KB Output is correct
7 Correct 29 ms 1508 KB Output is correct