Submission #40952

#TimeUsernameProblemLanguageResultExecution timeMemory
40952wzyIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
604 ms21464 KiB
#include <stdio.h> #include <vector> #include <stdint.h> #include <algorithm> using namespace std; #define pb push_back #define int long long int ans = 1 , v1[50] , v2[50] , n , m; int32_t main(){ scanf("%lld%lld" , &n , &m); int sz1 = n / 2 , sz2 = n - sz1; for(int i = 0 ; i < n;i++){ if(sz1){ scanf("%lld" , &v1[n/2 - sz1]); sz1--; } else{ scanf("%lld" , &v2[(n - n/2) - sz2]); sz2--; } } vector<int> value1 , value2; sz1 = n/2 , sz2 = n - sz1; for(int i = 1 ; i < (1<<sz1) ; i++){ int sum = 0; for(int j = 0 ; j < n ; j++){ if(1<<j & i) sum += v1[j]; } if(sum <= m) value1.pb(sum); } for(int i = 1 ; i < (1<<sz2) ; i++){ int sum = 0; for(int j = 0 ; j < n ; j++){ if(1<<j & i) sum += v2[j]; } if(sum <= m) value2.pb(sum); } ans += value1.size() + value2.size(); sort(value1.begin() , value1.end()); sort(value2.begin() , value2.end()); for(int i = 0 ; i < value1.size() ; i++){ int l = 0 , r = (int)value2.size() - 1; int ansj = -1; while(l<= r){ int mid = (l+r)/2; if(value2[mid] + value1[i] <= m){ l = mid + 1; ansj = max(ansj , mid); } else r = mid - 1; } if(ansj != -1) ans += ansj + 1; } printf("%lld\n" , ans); }

Compilation message (stderr)

bobek.cpp: In function 'int32_t main()':
bobek.cpp:45:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0 ; i < value1.size() ; i++){
                    ^
bobek.cpp:12:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld" , &n , &m);
                             ^
bobek.cpp:16:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld" , &v1[n/2 - sz1]);
                                  ^
bobek.cpp:20:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld" , &v2[(n - n/2) - sz2]);
                                        ^
#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...