답안 #118769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118769 2019-06-19T16:55:02 Z silxikys Ice Hockey World Championship (CEOI15_bobek) C++14
30 / 100
1000 ms 66296 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int maxn = 45;

struct SegDyn
{
	ll s, e, m; //represents range [s,e]
	SegDyn *l, *r;
	ll 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, ll 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
	}

	ll getsum(ll se, ll en) {
		if (se <= s && e <= en) return sum;
		ll res = 0;
		if (l && se <= m) res += l->getsum(se,en);
		if (r && en > m) res += r->getsum(se,en);
		return res;	
	}
};

int N, M;
ll A[maxn], B[maxn];

int main()
{
	cin >> N >> M;
	int split = N/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';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 2020 KB Output is correct
2 Correct 517 ms 30516 KB Output is correct
3 Execution timed out 1094 ms 66296 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 3064 KB Output is correct
2 Correct 169 ms 10448 KB Output is correct
3 Correct 489 ms 1832 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 20 ms 384 KB Output is correct
6 Correct 52 ms 4344 KB Output is correct
7 Correct 93 ms 30624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 325 ms 20984 KB Output is correct
2 Correct 636 ms 18808 KB Output is correct
3 Correct 599 ms 19548 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 223 ms 256 KB Output is correct
6 Execution timed out 1040 ms 2808 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 327 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 490 ms 476 KB Output isn't correct
2 Halted 0 ms 0 KB -