Submission #1118938

#TimeUsernameProblemLanguageResultExecution timeMemory
1118938adaawfDetecting Molecules (IOI16_molecules)C++17
100 / 100
47 ms7868 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; long long int c[200005]; vector<int> find_subset(int l, int u, vector<int> a) { vector<pair<int, int>> v; v.push_back({0, 0}); for (int i = 0; i < a.size(); i++) { v.push_back({a[i], i}); } sort(v.begin(), v.end()); int n = v.size() - 1; for (int i = 1; i <= n; i++) c[i] = c[i - 1] + v[i].first; for (int i = 1; i <= n; i++) { if (c[i] > u) continue; if (c[n] - c[n - i] < l) continue; long long int h = c[i]; vector<int> vv; for (int j = 1; j <= i; j++) vv.push_back(v[j].second); if (h >= l && h <= u) return vv; for (int j = i - 1; j >= 0; j--) { h -= a[vv[j]]; h += v[n - i + j + 1].first; vv[j] = v[n - i + j + 1].second; if (h >= l && h <= u) return vv; } } vector<int> vv; return vv; }

Compilation message (stderr)

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