Submission #651873

#TimeUsernameProblemLanguageResultExecution timeMemory
651873alvinpiterDetecting Molecules (IOI16_molecules)C++17
100 / 100
56 ms8608 KiB
#include "molecules.h" #include<bits/stdc++.h> using namespace std; #define LL long long int std::vector<int> find_subset(int l, int u, std::vector<int> w) { vector<pair<int, int> > indexedWeights; for (int i = 0; i < w.size(); i++) { indexedWeights.push_back({w[i], i}); } sort(indexedWeights.begin(), indexedWeights.end()); vector<LL> prefixSum; prefixSum.push_back(indexedWeights[0].first); for (int i = 1; i < indexedWeights.size(); i++) { prefixSum.push_back(indexedWeights[i].first + prefixSum.back()); } for (int i = 0; i < indexedWeights.size(); i++) { int lo = i, hi = indexedWeights.size() - 1, mid; while (hi >= lo) { mid = (lo + hi)/2; LL sum = prefixSum[mid] - (i == 0 ? 0 : prefixSum[i - 1]); if (sum < l) { lo = mid + 1; } else { hi = mid - 1; } } LL sum = prefixSum[lo] - (i == 0 ? 0 : prefixSum[i - 1]); if (sum >= l && sum <= u) { vector<int> result; for (int j = i; j <= lo; j++) { result.push_back(indexedWeights[j].second); } return result; } } vector<int> result; return result; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:8:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |   for (int i = 0; i < w.size(); i++) {
      |                   ~~^~~~~~~~~~
molecules.cpp:17:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |   for (int i = 1; i < indexedWeights.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~~~~~~
molecules.cpp:21:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for (int i = 0; i < indexedWeights.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...