Submission #118784

# Submission time Handle Problem Language Result Execution time Memory
118784 2019-06-19T17:49:55 Z silxikys Ice Hockey World Championship (CEOI15_bobek) C++14
50 / 100
1000 ms 634396 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
const int maxn = 40;
 
struct SegDyn
{
	ll s, e, m; //represents range [s,e]
	SegDyn *l, *r;
	int sum; //sum for this interval
	SegDyn(ll _s, ll _e) {
		s = _s;
		e = _e;
		m = (s+e)/2;
		l = NULL;
		r = NULL;
		sum = 0;
	}
 
	void prepareL() { if (l == NULL) l = new SegDyn(s,m); }
	void prepareR() { if (r == NULL) r = new SegDyn(m+1,e); }
 
	void pull() {
		sum = 0;
		if (l) sum += l->sum;
		if (r) sum += r->sum;
	}
 
	void add(ll idx, int del) { //a[idx] += del
		//cout << s << ' ' << e << '\n';
		if (s == e && s == idx) {
			//at the node, stop
			sum += del;
			return;
		}
		if (idx <= m) {
			prepareL();
			assert(l);
			l->add(idx,del);
		}
		else {
			prepareR();
			r->add(idx,del);
		}
		pull(); //updates current node based on the children
	}
 
	int getsum(ll se, ll en) {
		if (se <= s && e <= en) return sum;
		int res = 0;
		if (l && se <= m) res += l->getsum(se,en);
		if (r && en > m) res += r->getsum(se,en);
		return res;	
	}
};
 
int N;
ll M;
ll A[maxn], B[maxn];
 
int main()
{
	cin >> N >> M;
	int split = max(1,N/2-2);
	for (int i = 0; i < split; i++) {
		cin >> A[i];
	}
    for (int i = split; i < N; i++) {
        cin >> B[i-split];
    }
	SegDyn *root = new SegDyn(0,1e18+5);
	for (int i = 0; i < (1<<split); i++) {
        ll total = 0;
        for (int j = 0; j < split; j++) {
            if (i & (1<<j)) total += A[j];
        }
        root->add(total,1);
    }
 
    ll ans = 0;
    for (int i = 0; i < (1<<(N-split)); i++) {
        ll total = 0;
        for (int j = 0; j < N-split; j++) {
            if (i & (1<<j)) total += B[j];
        }
        if (total <= M) {
            ans += root->getsum(0,M-total);
        }
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 896 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 205 ms 1536 KB Output is correct
2 Correct 836 ms 14748 KB Output is correct
3 Execution timed out 1048 ms 41084 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 238 ms 2340 KB Output is correct
2 Correct 298 ms 4832 KB Output is correct
3 Correct 820 ms 1656 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 42 ms 256 KB Output is correct
6 Correct 67 ms 2808 KB Output is correct
7 Correct 37 ms 9860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 630 ms 8312 KB Output is correct
2 Execution timed out 1077 ms 11000 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 270692 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 276 ms 36244 KB Output is correct
2 Correct 932 ms 129528 KB Output is correct
3 Correct 67 ms 18304 KB Output is correct
4 Correct 70 ms 19064 KB Output is correct
5 Correct 629 ms 384 KB Output is correct
6 Correct 99 ms 32120 KB Output is correct
7 Execution timed out 1116 ms 634396 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1112 ms 511620 KB Time limit exceeded
2 Halted 0 ms 0 KB -