답안 #118785

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118785 2019-06-19T17:51:11 Z silxikys Ice Hockey World Championship (CEOI15_bobek) C++14
60 / 100
1000 ms 661092 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-1);
	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 256 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 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 4 ms 1580 KB Output is correct
7 Correct 2 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1536 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 3 ms 304 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 1844 KB Output is correct
2 Correct 571 ms 22136 KB Output is correct
3 Execution timed out 1080 ms 55832 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 2680 KB Output is correct
2 Correct 179 ms 7244 KB Output is correct
3 Correct 497 ms 1712 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 25 ms 384 KB Output is correct
6 Correct 50 ms 3584 KB Output is correct
7 Correct 56 ms 17272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 416 ms 13688 KB Output is correct
2 Correct 828 ms 15224 KB Output is correct
3 Correct 826 ms 15620 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 333 ms 384 KB Output is correct
6 Correct 717 ms 2692 KB Output is correct
7 Correct 483 ms 91516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1105 ms 525048 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 259 ms 70008 KB Output is correct
2 Correct 906 ms 250944 KB Output is correct
3 Correct 79 ms 35316 KB Output is correct
4 Correct 90 ms 36728 KB Output is correct
5 Correct 345 ms 504 KB Output is correct
6 Correct 123 ms 61944 KB Output is correct
7 Execution timed out 1113 ms 661092 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1080 ms 559004 KB Time limit exceeded
2 Halted 0 ms 0 KB -