Submission #426448

#TimeUsernameProblemLanguageResultExecution timeMemory
426448dariascDetecting Molecules (IOI16_molecules)C++14
0 / 100
1 ms300 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; vector<int> return_range(vector<pair<long long, int>> prefix, int i, int j) { vector<int> ans(j - i + 1); for (int k = 0; k < ans.size(); k++) { ans[k] = prefix[i + k].second; } return ans; } std::vector<int> find_subset(int l, int u, std::vector<int> w) { vector<pair<long long, int>> molecules(w.size()); for (int i = 0; i < w.size(); i++) { molecules[i] = {w[i], i}; } sort(molecules.begin(), molecules.end()); // make prefix sum for (int i = 1; i < molecules.size(); i++) { molecules[i].first += molecules[i-1].first; } int j = 0; for (int i = 0; i < molecules.size(); i++) { int weight = molecules[i].first; if (weight > u) { while (j < i) { int x = weight - molecules[j].first; if (l <= x && x <= u) { return return_range(molecules, j+1, i); } else if (x < l) { break; } j++; } } else if (l <= weight && weight <= u) { vector<int> ans = {i}; return ans; } } return std::vector<int>(0); }

Compilation message (stderr)

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