Submission #957506

#TimeUsernameProblemLanguageResultExecution timeMemory
957506androDetecting Molecules (IOI16_molecules)C++14
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> #include "molecules.h" using namespace std; int check(int x, int l, int r) { return l >= x && x <= r; } std::vector<int> find_subset(int l, int u, std::vector<int> w) { int n = w.size(); map<int, deque<int>> ids; for(int i = 0; i < n; i++) { ids[w[i]].push_back(i); } sort(w.begin(), w.end()); vector<int> d(n + 1); for(int i = 0; i < n; i++) { for(int j = i; j < n; j++) { if(u - l >= w[j] - w[i]) { d[i] = j; } } } vector<int> ans; for(int i = 0; i < n; i++) { multiset<int> ms; for(int j = i; j < d[i]; j++) { ms.insert(w[j]); } // s + x <= r // x <= r - s int s = 0; int ok = 0; while(1) { auto it = ms.upper_bound(u - s); if(it == ms.begin()) { ans.clear(); break; } it--; int x = *it; s += x; ans.push_back(x); ms.erase(x); if(s >= l) { ok = 1; break; } } if(ok) { break; } ans.clear(); } vector<int> p; for(auto it : ans) { p.push_back(ids[it].front()); ids[it].pop_front(); } return p; }/* signed main(){ for(auto it:find_subset(10, 20, {15, 17, 16, 18}))cout<<it<<" "; }*/
#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...