Submission #742526

#TimeUsernameProblemLanguageResultExecution timeMemory
742526MODDIIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
297 ms20808 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair typedef long long ll; typedef pair<long long, long long> pll; typedef pair<int,int> pii; typedef vector<long long> vl; typedef vector<int> vi; int n; ll m; bool check_bit(int n, int bit){ int ok = n & (1 << bit); if(ok) return true; return false; } int main(){ cin>>n>>m; vl arr(n+1); for(int i =1; i <= n; i++) cin>>arr[i]; vl msk1, msk2; int k = n / 2; for(int i = 0; i < (1 << k); i++){ ll sum = 0; for(int j = 0; j < k; j++){ if(check_bit(i, j)) sum += arr[j+1]; } msk1.pb(sum); } for(int i = 0; i < (1 << n - k); i++){ ll sum = 0; for(int j = 0; j < n-k; j++){ if(check_bit(i, j)) sum += arr[j+k+1]; } msk2.pb(sum); } sort(msk1.begin(), msk1.end()); sort(msk2.begin(), msk2.end()); int j = 0; ll ans = 0; for(int i = msk1.size()-1; i >= 0; i--){ while(j < msk2.size() && msk2[j] + msk1[i] <= m) j++; ans += j; } cout<<ans<<endl; return 0; }

Compilation message (stderr)

bobek.cpp: In function 'int main()':
bobek.cpp:31:29: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   31 |  for(int i = 0; i < (1 << n - k); i++){
      |                           ~~^~~
bobek.cpp:44:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   while(j < msk2.size() && msk2[j] + msk1[i] <= m) 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...