Submission #447483

# Submission time Handle Problem Language Result Execution time Memory
447483 2021-07-26T14:18:01 Z ak2006 Ice Hockey World Championship (CEOI15_bobek) C++14
100 / 100
527 ms 8652 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void setIO()
{
    fast;
}
int n = 40;
ll m;
vl a(n);
int main()
{
    setIO();
    cin>>n>>m;
    for (int i = 0;i<n;i++)cin>>a[i];
    int pivot = n/2;
    //generate all subsets of the first pivot integers (0 to pivot - 1)
    //generate all subsets of the remaining n - pivot integers (pivot to n - 1)
    //sort the first subset and for each number in the second subset, find
    //the last position in the first subset such that the number there + the current element in the
    //subset is <= m
    //if sum + X > m
    //then X > m - sum
    vl firstSubset;
    for (int mask = 0;mask<(1<<pivot);mask++){
        ll sum = 0;
        for (int i = 0;i<pivot;i++)
            if (mask & (1<<i))sum += a[i];
        firstSubset.pb(sum);
    }
    sort(firstSubset.begin(),firstSubset.end());
    ll cnt = 0;
    for (int mask = 0;mask<(1<<(n - pivot));mask++){
        ll sum = 0;
        for (int i = pivot;i<n;i++)
            if (mask & (1<<(i - pivot)))sum += a[i];
        cnt += upper_bound(firstSubset.begin(),firstSubset.end(),m - sum) - firstSubset.begin();
    }
    cout<<cnt;
    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 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 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 0 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 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 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 204 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 204 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 35 ms 848 KB Output is correct
2 Correct 109 ms 2504 KB Output is correct
3 Correct 518 ms 8652 KB Output is correct
4 Correct 106 ms 2484 KB Output is correct
5 Correct 17 ms 976 KB Output is correct
6 Correct 9 ms 592 KB Output is correct
7 Correct 16 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 1484 KB Output is correct
2 Correct 36 ms 976 KB Output is correct
3 Correct 219 ms 4556 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 8 ms 700 KB Output is correct
6 Correct 16 ms 976 KB Output is correct
7 Correct 16 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 1484 KB Output is correct
2 Correct 173 ms 2504 KB Output is correct
3 Correct 167 ms 2504 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 96 ms 2504 KB Output is correct
6 Correct 262 ms 8620 KB Output is correct
7 Correct 90 ms 2484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 381 ms 4492 KB Output is correct
2 Correct 33 ms 848 KB Output is correct
3 Correct 11 ms 592 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 9 ms 592 KB Output is correct
6 Correct 188 ms 4536 KB Output is correct
7 Correct 16 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 976 KB Output is correct
2 Correct 102 ms 2504 KB Output is correct
3 Correct 10 ms 592 KB Output is correct
4 Correct 11 ms 592 KB Output is correct
5 Correct 119 ms 2564 KB Output is correct
6 Correct 22 ms 848 KB Output is correct
7 Correct 282 ms 8532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 436 ms 8628 KB Output is correct
2 Correct 37 ms 976 KB Output is correct
3 Correct 11 ms 592 KB Output is correct
4 Correct 527 ms 8640 KB Output is correct
5 Correct 140 ms 4552 KB Output is correct
6 Correct 16 ms 848 KB Output is correct
7 Correct 32 ms 1420 KB Output is correct