Submission #46015

# Submission time Handle Problem Language Result Execution time Memory
46015 2018-04-17T02:00:31 Z sorry_Benq Ice Hockey World Championship (CEOI15_bobek) C++17
100 / 100
496 ms 17488 KB
/**
* Sources: various
*/

#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pli;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
template<typename T>
ostream& operator<< (ostream& out, const pair<T, T>& v) {
    out << "{" << v.first << ", " << v.second << "}";
    return out;
}

template<typename T>
ostream& operator<< (ostream& out, const vector<T>& v) {
    out << "[";
    size_t last = v.size() - 1;
    for(size_t i = 0; i < v.size(); ++i) {
        out << v[i];
        if (i != last) 
            out << ", ";
    }
    out << "]";
    return out;
}

template<typename T>
ostream& operator<< (ostream& out, const set<T>& v) {
    out << "[";
    auto pen = v.end();
    pen--;
    for (auto it = v.begin(); it != v.end(); it++){
		out << *it;
		if (it != pen){
			out << ", ";
		}
	}
	out << "]";
    return out;
}

template<typename T>
ostream& operator<< (ostream& out, const Tree<T>& v) {
    out << "[";
    auto pen = v.end();
    pen--;
    for (auto it = v.begin(); it != v.end(); it++){
		out << *it;
		if (it != pen){
			out << ", ";
		}
	}
	out << "]";
    return out;
}

ll a[1 << 20];
ll b[1 << 20];

vector<ll> v1;
vector<ll> v2;

void dfs1(int loc, ll val, int mask){
	if (loc == v1.size()){
		a[mask] = val; return;
	}
	dfs1(loc + 1, val + v1[loc], mask | (1<<loc));
	dfs1(loc + 1, val, mask);
}

void dfs2(int loc, ll val, int mask){
	if (loc == v2.size()){
		b[mask] = val; return;
	}
	dfs2(loc + 1, val + v2[loc], mask | (1<<loc));
	dfs2(loc + 1, val, mask);
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int N; ll M; cin >> N >> M;
	for (int i = 0; i < N; i++){
		ll p; cin >> p;
		if (i%2 == 0){
			v1.pb(p);
		}
		else{
			v2.pb(p);
		}
	}
	dfs1(0, 0, 0);
	dfs2(0, 0, 0);
	int alen = (1 << ((int) v1.size()));
	int blen = (1 << ((int) v2.size()));
	sort(a, a + alen);
	sort(b, b + blen);
	int startpos = -1;
	while (((startpos + 1) < alen) && (b[0] + (a[startpos + 1]) <= M)){
		startpos++;
	}
	ll res = 0;
	for (int i = 0; i < blen; i++){
		res += (startpos + 1);
		if (i != blen - 1){
			while ((startpos >= 0) && (b[i + 1] + a[startpos] > M)){
				startpos--;
			}
		}
	}
	cout << res << endl;
}

// read!read!read!read!read!read!read!
// ll vs. int!

Compilation message

bobek.cpp: In function 'void dfs1(int, ll, int)':
bobek.cpp:92:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (loc == v1.size()){
      ~~~~^~~~~~~~~~~~
bobek.cpp: In function 'void dfs2(int, ll, int)':
bobek.cpp:100:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (loc == v2.size()){
      ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 496 KB Output is correct
2 Correct 2 ms 552 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 552 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 2 ms 552 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 696 KB Output is correct
3 Correct 2 ms 700 KB Output is correct
4 Correct 2 ms 704 KB Output is correct
5 Correct 2 ms 708 KB Output is correct
6 Correct 2 ms 712 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 844 KB Output is correct
2 Correct 2 ms 844 KB Output is correct
3 Correct 2 ms 844 KB Output is correct
4 Correct 2 ms 844 KB Output is correct
5 Correct 2 ms 844 KB Output is correct
6 Correct 2 ms 844 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 2368 KB Output is correct
2 Correct 73 ms 5060 KB Output is correct
3 Correct 472 ms 17376 KB Output is correct
4 Correct 67 ms 17376 KB Output is correct
5 Correct 11 ms 17376 KB Output is correct
6 Correct 8 ms 17376 KB Output is correct
7 Correct 16 ms 17376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 17376 KB Output is correct
2 Correct 25 ms 17376 KB Output is correct
3 Correct 144 ms 17376 KB Output is correct
4 Correct 2 ms 17376 KB Output is correct
5 Correct 6 ms 17376 KB Output is correct
6 Correct 17 ms 17376 KB Output is correct
7 Correct 17 ms 17376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 17376 KB Output is correct
2 Correct 103 ms 17376 KB Output is correct
3 Correct 144 ms 17376 KB Output is correct
4 Correct 2 ms 17376 KB Output is correct
5 Correct 86 ms 17376 KB Output is correct
6 Correct 425 ms 17412 KB Output is correct
7 Correct 132 ms 17412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 337 ms 17412 KB Output is correct
2 Correct 27 ms 17412 KB Output is correct
3 Correct 11 ms 17412 KB Output is correct
4 Correct 2 ms 17412 KB Output is correct
5 Correct 7 ms 17412 KB Output is correct
6 Correct 314 ms 17412 KB Output is correct
7 Correct 16 ms 17412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 17412 KB Output is correct
2 Correct 68 ms 17412 KB Output is correct
3 Correct 10 ms 17412 KB Output is correct
4 Correct 10 ms 17412 KB Output is correct
5 Correct 89 ms 17412 KB Output is correct
6 Correct 25 ms 17412 KB Output is correct
7 Correct 496 ms 17480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 457 ms 17480 KB Output is correct
2 Correct 25 ms 17480 KB Output is correct
3 Correct 11 ms 17480 KB Output is correct
4 Correct 437 ms 17488 KB Output is correct
5 Correct 107 ms 17488 KB Output is correct
6 Correct 16 ms 17488 KB Output is correct
7 Correct 33 ms 17488 KB Output is correct