Submission #975258

#TimeUsernameProblemLanguageResultExecution timeMemory
975258duckindogIce Hockey World Championship (CEOI15_bobek)C++17
100 / 100
238 ms22496 KiB
#include <bits/stdc++.h> using namespace std; const int N = 40 + 10; int n; long long m; long long a[N], b[N]; int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m; vector<long long> first = {0}, second = {0}; { int x = (n + 1 >> 1), y = n - x; for (int i = 1; i <= x; ++i) cin >> a[i]; for (int i = 1; i <= y; ++i) cin >> b[i]; for (int bit = 1; bit < (1 << x); ++bit) { long long sum = 0; for (int j = 1; j <= x; ++j) sum += (bit >> j - 1 & 1) * a[j]; if (sum <= m) first.push_back(sum); } for (int bit = 1; bit < (1 << y); ++bit) { long long sum = 0; for (int j = 1; j <= y; ++j) sum += (bit >> j - 1 & 1) * b[j]; if (sum <= m) second.push_back(sum); } } sort(first.begin(), first.end()); sort(second.begin(), second.end()); long long answer = 0; for (const auto& x : first) answer += upper_bound(second.begin(), second.end(), m - x) - second.begin(); cout << answer << "\n"; }

Compilation message (stderr)

bobek.cpp: In function 'int32_t main()':
bobek.cpp:16:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   16 |     int x = (n + 1 >> 1), y = n - x;
      |              ~~^~~
bobek.cpp:22:53: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   22 |       for (int j = 1; j <= x; ++j) sum += (bit >> j - 1 & 1) * a[j];
      |                                                   ~~^~~
bobek.cpp:28:53: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   28 |       for (int j = 1; j <= y; ++j) sum += (bit >> j - 1 & 1) * b[j];
      |                                                   ~~^~~
#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...