This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* 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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |