답안 #118789

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118789 2019-06-19T18:11:41 Z silxikys Ice Hockey World Championship (CEOI15_bobek) C++14
60 / 100
1000 ms 576040 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;
    ll tot = 0;
	int split = N/2;
	for (int i = 0; i < split; i++) {
		cin >> A[i];
        tot += A[i];
	}
    for (int i = split; i < N; i++) {
        cin >> B[i-split];
        tot += B[i-split];
    }
    if (tot <= M) {
        cout << (1LL<<N) << '\n';
        return 0;
    }
	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];
            if (total > M) {
                break;
            }
        }
        if (total <= M) 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) {
                break;
            }
        }
        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 256 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 380 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 3 ms 1024 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 3 ms 1024 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 Correct 6 ms 2816 KB Output is correct
2 Correct 4 ms 1664 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1152 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 Correct 86 ms 2052 KB Output is correct
2 Correct 523 ms 30412 KB Output is correct
3 Execution timed out 1068 ms 64612 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 2936 KB Output is correct
2 Correct 142 ms 10488 KB Output is correct
3 Correct 432 ms 1756 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 21 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 338 ms 21112 KB Output is correct
2 Correct 750 ms 19080 KB Output is correct
3 Correct 683 ms 19704 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 235 ms 364 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 576040 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 346 ms 135680 KB Output is correct
2 Execution timed out 1115 ms 489208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1122 ms 572252 KB Time limit exceeded
2 Halted 0 ms 0 KB -