Submission #450319

# Submission time Handle Problem Language Result Execution time Memory
450319 2021-08-02T13:48:42 Z BT21tata Ice Hockey World Championship (CEOI15_bobek) C++17
100 / 100
547 ms 20772 KB
#include<bits/stdc++.h>
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef long double ld;
#define SPEED ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define rall(v) (v).rbegin(),(v).rend()
#define all(v) (v).begin(),(v).end()
#define OK cerr<<"OK"<<endl<<flush
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define F first
#define S second
#define y0 jahdakdh
#define y1 jahsadakdakdh
#define endl '\n'
using namespace std;
const ll MOD=1e9+7;
// mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
 
ll n, m, a[45], ans;
vector<ll>v1, v2;

ll bs(ll x)
{
    ll l=0, r=v2.size()-1, mid;
    while(l<=r)
    {
        mid=(l+r)>>1;
        if(v2[mid]<=x) l=mid+1;
        else r=mid-1;
    }
    return l;
}

int main()
{
    SPEED;
    cin>>n>>m;
    for(int i=0; i<n; i++)
        cin>>a[i];
    // [0, n/2);
    for(ll i=0; i<(1<<(n>>1)); i++)
    {
        ll sum=0;
        for(ll j=0; j<(n>>1); j++)
        {
            if(i&(1<<j)) sum+=a[j];
        }
        if(sum<=m) v1.pb(sum);
    }

    // [n/2, n);
    for(ll i=0; i<(1<<(n-(n>>1))); i++)
    {
        ll sum=0;
        for(ll j=0; j<(n-(n>>1)); j++)
        {
            if(i&(1<<j)) sum+=a[j+(n>>1)];
        }
        if(sum<=m) v2.pb(sum);
    }
    sort(all(v2));
    for(ll u : v1)
    {
        // find num of elements in v2 that are <=m-v1[i]
        ans+=bs(m-u);
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 2000 KB Output is correct
2 Correct 107 ms 5428 KB Output is correct
3 Correct 547 ms 20772 KB Output is correct
4 Correct 104 ms 5392 KB Output is correct
5 Correct 15 ms 1484 KB Output is correct
6 Correct 8 ms 952 KB Output is correct
7 Correct 9 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 2876 KB Output is correct
2 Correct 35 ms 2000 KB Output is correct
3 Correct 209 ms 10532 KB Output is correct
4 Correct 1 ms 232 KB Output is correct
5 Correct 7 ms 976 KB Output is correct
6 Correct 16 ms 1612 KB Output is correct
7 Correct 9 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 3516 KB Output is correct
2 Correct 153 ms 6600 KB Output is correct
3 Correct 152 ms 6564 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 89 ms 6568 KB Output is correct
6 Correct 272 ms 20712 KB Output is correct
7 Correct 54 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 372 ms 12780 KB Output is correct
2 Correct 33 ms 2000 KB Output is correct
3 Correct 13 ms 976 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 8 ms 924 KB Output is correct
6 Correct 233 ms 12724 KB Output is correct
7 Correct 9 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 2000 KB Output is correct
2 Correct 102 ms 5432 KB Output is correct
3 Correct 10 ms 960 KB Output is correct
4 Correct 10 ms 848 KB Output is correct
5 Correct 101 ms 6568 KB Output is correct
6 Correct 31 ms 2000 KB Output is correct
7 Correct 142 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 421 ms 20768 KB Output is correct
2 Correct 41 ms 1984 KB Output is correct
3 Correct 12 ms 976 KB Output is correct
4 Correct 502 ms 20760 KB Output is correct
5 Correct 146 ms 10544 KB Output is correct
6 Correct 16 ms 1612 KB Output is correct
7 Correct 17 ms 312 KB Output is correct