Submission #316323

#TimeUsernameProblemLanguageResultExecution timeMemory
316323CaroLindaIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
403 ms20948 KiB
#include <bits/stdc++.h> #define all(x) x.begin(),x.end() #define sz(x) (int)(x.size()) #define ll long long using namespace std ; bool isOn(int i, int m) { return ((1<<i)&m) != 0 ; } int main() { int n ; ll budget ; scanf("%d %lld", &n, &budget ) ; vector<ll> vec[2] ; vec[0].resize( max(n/2,0) ) ; vec[1].resize( max(n - (n/2) , 0) ) ; for(int i = 0 ; i < n/2 ; i++ ) scanf("%lld", &vec[0][i]) ; for(int i = n/2 , j = 0 ; i < n ; i++, j++ ) scanf("%lld", &vec[1][j]) ; vector<ll> ways[2] ; long long ans = 0LL ; for(int i = 0, qtd ; i < 2 ; i++ ) { qtd = (int)( vec[i].size() ) ; for(int j = 0 ; j < (1<<qtd) ; j++ ) { long long mySum = 0 ; for(int g = 0 ; g < qtd ; g++ ) if(isOn(g,j)) mySum += vec[i][g] ; ways[i].push_back(mySum) ; } sort(all(ways[i])) ; } for(long long mySum : ways[0] ) { int l = 0 , r = sz(ways[1])-1 , mid , best = -1 ; while( l <= r ) { mid = (l+r)>>1 ; if( mySum + ways[1][mid] <= budget ) { best = mid ; l = mid+1 ; } else r = mid-1 ; } ans += 1LL + (ll)best ; } printf("%lld\n" , ans ) ; }

Compilation message (stderr)

bobek.cpp: In function 'int main()':
bobek.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  scanf("%d %lld", &n, &budget ) ;
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bobek.cpp:22:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |  for(int i = 0 ; i < n/2 ; i++ ) scanf("%lld", &vec[0][i]) ;
      |                                  ~~~~~^~~~~~~~~~~~~~~~~~~~
bobek.cpp:23:52: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |  for(int i = n/2 , j = 0 ; i < n ; i++, j++ ) scanf("%lld", &vec[1][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...