Submission #208176

# Submission time Handle Problem Language Result Execution time Memory
208176 2020-03-10T07:15:49 Z fr_klr Ice Hockey World Championship (CEOI15_bobek) C++14
0 / 100
1000 ms 90796 KB
//I wanna live before i die
#include<bits/stdc++.h>
using namespace std;

const long long maxn = (1 << 20) + 20, inf = 1e16 + 69, V = 5, delta = 998244353;
long long n, m;
map<long long, long long> w;
vector<pair<long long, long long> > part;
vector<long long> v;
long long dp[maxn];
long long find_first(long long mask){
    for(long long i = 0;; i++)
        if((1 << i) & mask)
            return i;
}

void first_part(long long sz){
    for(long long mask = 1; mask < (1 << sz); mask++){
        long long u = find_first(mask);
        if(__builtin_popcount(mask) == 1)
            dp[mask] = v[u];
        else
            dp[mask] = dp[mask - (mask & -mask)] + v[u];
        w[dp[mask]]++;
    }
}

long long make_part_1(){
    part.push_back(make_pair(0, 1));
    long long A = 1;
    for(auto e : w){
        long long f = e.first;
        long long s = part[part.size() - 1].second + e.second;
        part.push_back(make_pair(f, s));
        A = s;
    }
    return A;
}
long long find_amount(long long A){
    if(A < 0)
        return 0;
    pair<long long, long long> p = {A, inf};
    long long e = upper_bound(part.begin(), part.end(), p) - part.begin();
    return part[e - 1].second;
}
long long second_part(long long sz){
    memset(dp, 0, sizeof dp);
    long long Ans = 0;
    for(long long mask = 1; mask < (1 << (n - sz)); mask++){
        long long u = find_first(mask) + sz;
        if(__builtin_popcount(mask) == 1)
            dp[mask] = v[u];
        else
            dp[mask] = dp[mask - (mask & -mask)] + v[u];

        Ans += find_amount(m - dp[mask] - 1);
    }
    return Ans;
}
void input(){
    cin >> n >> m;
    for(long long i = 0; i < n; i++){
        long long tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
}
void calc(){
    first_part(n / 2);
    cout << (make_part_1() + second_part(n / 2)) << endl;
}
int main(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    input();
    calc();
}
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 8568 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 8568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 8568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8568 KB Output is correct
2 Incorrect 9 ms 8568 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 9588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 10096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 94 ms 16996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 790 ms 49748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 13808 KB Output is correct
2 Correct 267 ms 29152 KB Output is correct
3 Correct 25 ms 11248 KB Output is correct
4 Incorrect 25 ms 11248 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 90796 KB Time limit exceeded
2 Halted 0 ms 0 KB -