Submission #768962

#TimeUsernameProblemLanguageResultExecution timeMemory
768962anha3k25cvpIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
818 ms24928 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define dl double #define st first #define nd second #define II pair <int, int> using namespace std; const int N = 5 + 1e5; const int inf = 7 + 1e9; struct fenwick { int n; vector <ll> tree; fenwick (int _n = 0) : n(_n) { tree.assign(n + 1, 0); } void update(int x) { for (int i = x; i <= n; i += i & -i) tree[i] ++; } ll get(int x) { ll ans = 0; for (int i = x; i > 0; i -= i & -i) ans += tree[i]; return ans; } }; int main() { #define TASKNAME "" ios_base :: sync_with_stdio (0); cin.tie (0); if ( fopen( TASKNAME".inp", "r" ) ) { freopen (TASKNAME".inp", "r", stdin); freopen (TASKNAME".out", "w", stdout); } int n; ll m; cin >> n >> m; int n_ = n / 2; vector <ll> a(n_, 0), c; for (int i = 0; i < n_; i ++) cin >> a[i]; for (int mask = 0; mask < (1 << n_); mask ++) { ll sum = 0; for (int si = mask; si > 0; si ^= si & -si) { int i = __builtin_ctz(si & -si); sum += a[i]; } c.push_back(sum); } for (int mask = 0; mask < (1 << n_); mask ++) { ll sum = 0; for (int si = mask; si > 0; si ^= si & -si) { int i = __builtin_ctz(si & -si); sum += a[i]; } c.push_back(sum); } sort(c.begin(), c.end()); c.resize(unique(c.begin(), c.end()) - c.begin()); fenwick f(c.size()); for (int mask = 0; mask < (1 << n_); mask ++) { ll sum = 0; for (int si = mask; si > 0; si ^= si & -si) { int i = __builtin_ctz(si & -si); sum += a[i]; } sum = lower_bound(c.begin(), c.end(), sum) - c.begin() + 1; f.update(sum); } n_ = n - n_; a.assign(n_, 0); for (int i = 0; i < n_; i ++) cin >> a[i]; ll ans = 0; for (int mask = 0; mask < (1 << n_); mask ++) { ll sum = 0; for (int si = mask; si > 0; si ^= si & -si) { int i = __builtin_ctz(si & -si); sum += a[i]; } sum = upper_bound(c.begin(), c.end(), m - sum) - c.begin(); ans += f.get(sum); } cout << ans; return 0; }

Compilation message (stderr)

bobek.cpp: In function 'int main()':
bobek.cpp:37:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen (TASKNAME".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
bobek.cpp:38:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen (TASKNAME".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...