Submission #298581

#TimeUsernameProblemLanguageResultExecution timeMemory
298581BeanZIce Hockey World Championship (CEOI15_bobek)C++14
70 / 100
1060 ms82624 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 2e5 + 5; ll a[N]; map<ll, ll> mem; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("A.INP", "r")){ freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); } ll n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; ll mid = n / 2; ll rem = n - n / 2; for (int i = 0; i < (1 << mid); i++){ ll sum = 0; for (int j = 0; j < mid; j++){ if (i & (1 << j)){ sum = sum + a[j]; } } mem[sum]++; } vector<pair<ll, ll>> val; for (auto j : mem){ val.push_back({j.first, j.second}); } for (int i = 1; i < val.size(); i++){ val[i].second += val[i - 1].second; //cout << val[i].first << " " << val[i].second << endl; } ll ans = 0; for (int i = 0; i < (1 << rem); i++){ ll sum = 0; for (int j = 0; j < rem; j++){ if (i & (1 << j)){ sum = sum + a[mid + j]; } } if (sum > k) continue; ll l = 0, h = val.size() - 1; ll res = k - sum; while (l <= h){ ll mid = (l + h) >> 1; if (val[mid].first > res) h = mid - 1; else l = mid + 1; } if (h >= 0) ans = ans + val[h].second; } cout << ans; } /* */

Compilation message (stderr)

bobek.cpp: In function 'int main()':
bobek.cpp:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for (int i = 1; i < val.size(); i++){
      |                         ~~^~~~~~~~~~~~
bobek.cpp:14:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   14 |                 freopen("A.INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
bobek.cpp:15:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   15 |                 freopen("A.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...