Submission #981885

#TimeUsernameProblemLanguageResultExecution timeMemory
981885LOLOLOIce Hockey World Championship (CEOI15_bobek)C++17
100 / 100
176 ms22832 KiB
#include <bits/stdc++.h> using namespace std; int n; long long M; long long a[44]; long long ans; vector< long long > v1, v2; void bt(int pos, int lim, long long sum, vector<long long> &v) { if (pos == lim) { v.push_back(sum); return; } bt(pos + 1, lim, sum, v); bt(pos + 1, lim, sum + a[pos], v); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> M; for (int i = 0; i < n; ++i) cin >> a[i]; bt(0, n / 2, 0, v1); bt(n / 2, n, 0, v2); sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); int ptr = v2.size() - 1; for (int i = 0; i < v1.size(); ++i) { if (v1[i] > M) break; while(ptr >= 0 && v2[ptr] > M - v1[i]) --ptr; // [0...ptr] ans += ptr + 1; } printf("%lld\n", ans); }

Compilation message (stderr)

bobek.cpp: In function 'int main()':
bobek.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for (int i = 0; i < v1.size(); ++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...