# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1121767 | vjudge1 | Ice Hockey World Championship (CEOI15_bobek) | C++17 | 297 ms | 23212 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
# define int long long
const int maxn = 1e6 + 5;
void solve()
{
int n, k, cnt = 0;
cin >> n >> k;
vector < int > a(n);
vector < int > pr1;
vector < int > pr2;
vector < int > p;
vector < int > q;
for(int i = 0; i < n; i++)
cin >> a[i];
for(int i = 0; i < n / 2 + (n % 2); i++)
pr1.push_back(a[i]);
for(int i = n / 2 + (n % 2); i < n; i++)
pr2.push_back(a[i]);
for(int i = 1; i < pow(2, pr1.size()); i++)
{
int ans = 0;
for(int j = 0; j < pr1.size(); j++)
{
if(i & (1 << j))
{
ans += pr1[j];
}
}
p.push_back(ans);
}
for(int i = 1; i < pow(2, pr2.size()); i++)
{
int ans = 0;
for(int j = 0; j < pr2.size(); j++)
{
if(i & (1 << j))
ans += pr2[j];
}
q.push_back(ans);
}
sort(q.begin(), q.end());
for(int i = 0; i < p.size(); i++)
{
if(p[i] <= k)
cnt++;
}
for(int i = 0; i < q.size(); i++)
{
if(q[i] <= k)
cnt++;
}
for(int i = 0; i < p.size(); i++)
{
int chk = k - p[i];
int l = 0, r = q.size() - 1;
if(p[i] > chk) continue;
while(r > l)
{
int mid = (l + r) / 2;
if(q[mid] >= chk)
r = mid - 1;
else
l = mid + 1;
}
cnt += (l + 1);
}
cout << cnt + 1<< endl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt = 1;
// cin >> tt;
while(tt--)
solve();
}
Compilation message (stderr)
# | 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... |