Submission #241704

#TimeUsernameProblemLanguageResultExecution timeMemory
241704godwindDetecting Molecules (IOI16_molecules)C++14
100 / 100
76 ms6252 KiB
#include <iostream> #include <vector> #include <algorithm> #include <set> #include <map> #include <cstring> #include <cmath> #include <functional> #include "molecules.h" using namespace std; #define left left228 #define right right228 #define all(v) v.begin(), v.end() vector<int> find_subset(int l, int u, vector<int> w) { int n = (int)w.size(); vector< pair<int, int> > a; for (int i = 0; i < n; ++i) { a.emplace_back( w[i], i ); } sort(a.begin(), a.end()); long long left = 0, right = 0; for (int k = 1; k <= n; ++k) { left += a[k - 1].first; right += a[n - k].first; if (l <= left && left <= u) { vector<int> answer; for (int i = 0; i < k; ++i) { answer.emplace_back(a[i].second); } sort(all(answer)); return answer; } if (l <= right && right <= u) { vector<int> answer; for (int i = n - 1; i > n - 1 - k; --i) { answer.emplace_back(a[i].second); } sort(all(answer)); return answer; } if (left < l && right > u) { vector<int> answer; for (int i = 0; i < k; ++i) { answer.emplace_back(a[i].second); } vector<int> ind; for (int i = n - 1; i > n - 1 - k; --i) { ind.emplace_back(a[i].second); } for (int i = 0; i < k; ++i) { left -= w[ answer[i] ]; left += w[ ind[i] ]; answer[i] = ind[i]; if (l <= left && left <= u) { break; } } return answer; } } return vector<int>(0); }
#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...