Submission #710639

# Submission time Handle Problem Language Result Execution time Memory
710639 2023-03-15T13:00:16 Z WonderfulWhale Ice Hockey World Championship (CEOI15_bobek) C++17
100 / 100
442 ms 33360 KB
#include<bits/stdc++.h>
using namespace std;

#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

int tab[49];

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, Sum;
	cin >> n >> Sum;
	for(int i=0;i<n;i++) {
		cin >> tab[i];
	}
	int m = n/2;
	if(n==1) {
		if(tab[0]<=Sum) {
			cout << "2\n";
		} else {
			cout << "1\n";
		}
		return 0;
	}
	int m2 = n-m;
	vector<int> v1;
	for(int i=0;i<(1<<m);i++) {
		int s = 0;
		for(int j=0;j<m;j++) {
			if(i&(1<<j)) {
				s+=tab[j];
			}
		}
		v1.pb(s);
	}
	vector<int> v2;
	for(int i=0;i<(1<<m2);i++) {
		int s = 0;
		for(int j=m;j<n;j++) {
			if(i&(1<<(j-m))) {
				s+=tab[j];
			}
		}
		v2.pb(s);
	}
	sort(all(v1));
	sort(all(v2));
	vector<pii> pre(sz(v2));
	for(int i=0;i<sz(v2);i++) {
		pre[i] = {v2[i], i+1};
	}
	int ans = 0;
	for(int i=0;i<sz(v1);i++) {
		if(v1[i]>Sum) break;
		int s = -1;
		int e = sz(v2);
		while(e-s>1) {
			int m = (e+s)/2;
			if(pre[m].st<=Sum-v1[i]) s = m;
			else e = m;
		}
		ans += pre[s].nd;
	}
	cout << ans << "\n";

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 3920 KB Output is correct
2 Correct 116 ms 8636 KB Output is correct
3 Correct 442 ms 33292 KB Output is correct
4 Correct 97 ms 8648 KB Output is correct
5 Correct 16 ms 2476 KB Output is correct
6 Correct 9 ms 1492 KB Output is correct
7 Correct 19 ms 2464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 4436 KB Output is correct
2 Correct 33 ms 4060 KB Output is correct
3 Correct 183 ms 16956 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 8 ms 1496 KB Output is correct
6 Correct 23 ms 2516 KB Output is correct
7 Correct 18 ms 2524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 7628 KB Output is correct
2 Correct 141 ms 14996 KB Output is correct
3 Correct 144 ms 14884 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 103 ms 14808 KB Output is correct
6 Correct 388 ms 33288 KB Output is correct
7 Correct 108 ms 14800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 288 ms 29144 KB Output is correct
2 Correct 31 ms 4052 KB Output is correct
3 Correct 10 ms 1364 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 1492 KB Output is correct
6 Correct 286 ms 29212 KB Output is correct
7 Correct 18 ms 2520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 4044 KB Output is correct
2 Correct 96 ms 8736 KB Output is correct
3 Correct 10 ms 1492 KB Output is correct
4 Correct 10 ms 1364 KB Output is correct
5 Correct 109 ms 14780 KB Output is correct
6 Correct 31 ms 4036 KB Output is correct
7 Correct 300 ms 33360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 440 ms 33284 KB Output is correct
2 Correct 32 ms 4052 KB Output is correct
3 Correct 13 ms 1492 KB Output is correct
4 Correct 441 ms 33356 KB Output is correct
5 Correct 169 ms 16860 KB Output is correct
6 Correct 25 ms 2516 KB Output is correct
7 Correct 38 ms 4436 KB Output is correct