Submission #510066

#TimeUsernameProblemLanguageResultExecution timeMemory
510066CraniXortIce Hockey World Championship (CEOI15_bobek)C++17
100 / 100
210 ms33424 KiB
#include <bits/stdc++.h> #define fin std::cin #define fout std::cout // std::ifstream fin("hockey.in"); // std::ofstream fout("hockey.out"); long long maxsum; void compute(std::vector <long long>& v) { std::vector <long long> x; std::stack <long long> toAdd; x.push_back(0); for(auto value: v) { for(auto sum: x) toAdd.push(value + sum); while(toAdd.empty() == false) { if(toAdd.top() <= maxsum) x.push_back(toAdd.top()); toAdd.pop(); } } std::sort(x.begin(), x.end()); v = x; } void print(std::vector <long long> &v) { for(int i: v) fout << i << ' '; fout << '\n'; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; fin >> n >> maxsum; std::vector <long long> a, b; for(long long i = 0, value; i < n / 2; i ++) { fin >> value; a.push_back(value); } for(long long i = n / 2, value; i < n; i ++){ fin >> value; b.push_back(value); } compute(a); compute(b); // print(a); // print(b); long long ans = 0; for(int i = 0, j = b.size() - 1; i < a.size(); i ++) { while(j >= 0 and a[i] + b[j] > maxsum) j --; ans = ans + (j + 1); } fout << ans << '\n'; return 0; }

Compilation message (stderr)

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