Submission #810647

#TimeUsernameProblemLanguageResultExecution timeMemory
810647wortelwormDetecting Molecules (IOI16_molecules)C++17
46 / 100
1069 ms2260 KiB
// #include "grader.cpp" #include "molecules.h" #include <bits/stdc++.h> using namespace std; std::vector<int> find_subset(int lower, int upper, std::vector<int> w) { // sum -> last weight index vector<int> sums(lower, -1); sums[0] = 0; for (int j = 0; j < w.size(); j++) { for (int i = lower - 1; i >= 0; i--) { if (sums[i] == -1) { continue; } int total_weight = w[j] + i; if (total_weight >= lower && total_weight <= upper) { // Done! // indexes of weights vector<int> result; int current_weight = total_weight; int current_index = j; while (current_weight != 0) { result.push_back(current_index); current_weight -= w[current_index]; current_index = sums[current_weight]; } return result; } if (sums[total_weight] != -1) { // already found continue; } sums[total_weight] = j; } } return {}; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int j = 0; j < w.size(); 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...