Submission #28748

#TimeUsernameProblemLanguageResultExecution timeMemory
28748rondojimIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
649 ms13548 KiB
#include <stdio.h> #include <vector> #include <algorithm> using namespace std; const int MAXN = 45; typedef long long ll; ll N, K, A[MAXN], result; int main(){ #ifdef DEBUG freopen("input.txt", "r", stdin); #endif scanf("%lld %lld", &N, &K); for(int i=0; i<N; ++i) scanf("%lld", &A[i]); int middle = N / 2, remain = N - N / 2; vector<ll> sums; for(int bitm=0; bitm<(1<<middle); ++bitm){ ll sum = 0; for(int i=0; i<middle; ++i) if(bitm & (1<<i)) sum += A[i]; sums.push_back(sum); } sort(sums.begin(), sums.end()); for(int bitm=0; bitm<(1<<remain); ++bitm){ ll sum = 0; for(int i=0; i<remain; ++i) if(bitm & (1<<i)) sum += A[middle + i]; int lo = 0, hi = sums.size() - 1, res = -1, mid; while(lo <= hi){ mid = (lo + hi)>>1; if(sums[mid] + sum > K) hi = mid - 1; else res = mid, lo = mid + 1; } if(res != -1) result += res + 1; } printf("%lld\n", result); return 0; }

Compilation message (stderr)

bobek.cpp: In function 'int main()':
bobek.cpp:17:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &N, &K);
                             ^
bobek.cpp:18:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i=0; i<N; ++i) scanf("%lld", &A[i]);
                                              ^
#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...