Submission #590035

# Submission time Handle Problem Language Result Execution time Memory
590035 2022-07-05T13:32:20 Z Blagojce Ice Hockey World Championship (CEOI15_bobek) C++11
100 / 100
321 ms 20892 KB
#include <bits/stdc++.h>
#define fr(i, n, m) for(ll i = (n); i < (m); i ++)
#define st first
#define nd second
#define pb push_back
#define pq priority_queue
#define all(x) begin(x), end(x)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int n;
ll m;

ll a[40];

int main(){
	cin >> n >> m;
	fr(i, 0, n){
		cin >> a[i];
	}
	
	int p1 = n/2;
	int p2 = n-p1;
	
	vector<ll> v1;
	fr(i, 0, (1<<p1)){
		ll sum = 0;
		fr(j, 0, p1){
			if(i&(1LL<<j)){
				sum += a[j];
			}
		}
		if(sum <= m){
			v1.pb(sum);
		}
	}
	
	vector<ll> v2;
	fr(i, 0, (1<<p2)){
		ll mask = (i<<p1);
		ll sum = 0;
		fr(j, p1, p1+p2){
			if(mask&(1LL<<j)){
				sum += a[j];
			}
		}
		if(sum <= m){
			v2.pb(sum);
		}
		
	}
	sort(all(v1));
	sort(all(v2));
	
	int pos = 1;
	ll ans = 0;
	for(int i = (int)v1.size()-1; i >= 0; i --){
		while(pos < (int)v2.size() && v2[pos] + v1[i] <= m){
			++pos;
		}
		ans += pos;
	
	}
	cout<<ans<<endl;
	
	
	
	
	
	
	
	
	
}
# Verdict Execution time Memory Grader output
1 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1992 KB Output is correct
2 Correct 68 ms 5436 KB Output is correct
3 Correct 287 ms 20892 KB Output is correct
4 Correct 68 ms 5384 KB Output is correct
5 Correct 12 ms 1548 KB Output is correct
6 Correct 8 ms 964 KB Output is correct
7 Correct 7 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2760 KB Output is correct
2 Correct 24 ms 1872 KB Output is correct
3 Correct 115 ms 10512 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 6 ms 852 KB Output is correct
6 Correct 19 ms 1484 KB Output is correct
7 Correct 8 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 3500 KB Output is correct
2 Correct 109 ms 6564 KB Output is correct
3 Correct 101 ms 6584 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 69 ms 6544 KB Output is correct
6 Correct 254 ms 20788 KB Output is correct
7 Correct 42 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 210 ms 12736 KB Output is correct
2 Correct 24 ms 1960 KB Output is correct
3 Correct 8 ms 852 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 7 ms 940 KB Output is correct
6 Correct 221 ms 12676 KB Output is correct
7 Correct 7 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1992 KB Output is correct
2 Correct 67 ms 5444 KB Output is correct
3 Correct 7 ms 852 KB Output is correct
4 Correct 8 ms 932 KB Output is correct
5 Correct 74 ms 6580 KB Output is correct
6 Correct 25 ms 1884 KB Output is correct
7 Correct 118 ms 280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 279 ms 20800 KB Output is correct
2 Correct 25 ms 1872 KB Output is correct
3 Correct 9 ms 852 KB Output is correct
4 Correct 321 ms 20800 KB Output is correct
5 Correct 93 ms 10544 KB Output is correct
6 Correct 18 ms 1572 KB Output is correct
7 Correct 14 ms 212 KB Output is correct