Submission #392184

#TimeUsernameProblemLanguageResultExecution timeMemory
392184HegdahlDetecting Molecules (IOI16_molecules)C++17
9 / 100
1 ms276 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> find_subset(int _l, int _u, vector<int> w) { ll l = _l, u = _u; int n = w.size(); ll mn = 1LL<<60; for (int v : w) mn = min(mn, (ll)v); if (mn > u) return {}; vector<int> idxs(n); iota(idxs.begin(), idxs.end(), 0); sort(idxs.begin(), idxs.end(), [&](int i, int j){ return w[i] < w[j]; }); ll s = 0; vector<int> ans; int last = -1; for (int _i = 0; _i < n; ++_i) { int i = idxs[_i]; if (s + w[i] > u) { last = _i; break; } s += w[i]; ans.push_back(i); if (s >= l) return ans; } int _i = 0; while (_i+last < n && _i < ans.size()) { s -= w[ans[_i]]; ans[_i] = idxs[_i+last]; s += w[ans[_i]]; ++_i; if (s >= l) return ans; } return {}; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:42:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   while (_i+last < n && _i < ans.size()) {
      |                         ~~~^~~~~~~~~~~~
#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...