Submission #209107

#TimeUsernameProblemLanguageResultExecution timeMemory
209107my99nDetecting Molecules (IOI16_molecules)C++14
0 / 100
5 ms376 KiB
#include<bits/stdc++.h> using namespace std; #include "molecules.h" vector<int> find_subset(int l, int u, vector<int> w) { vector<int> ans; vector<pair<int,int>> s; for (int i = 0; i < w.size(); i++) s.push_back({w[i], i}); sort(s.begin(), s.end()); int wmax = (s.end()-1)->first, wmin = s.begin()->first; if (wmin > u) return vector<int>(0); if (l <= wmin and wmin <= u) return vector<int>(1, s[0].second); if (l <= wmax and wmax <= u) return vector<int>(1, s.back().second); // cerr << "fuck god" << endl; // case min <= max < l <= u map<int,int> m; int n = w.size(); queue<pair<int,int>> pre; m[0] = -1; for (int i = 0; i < n; i++) { for (auto j : m) { int key = j.first + w[i]; pre.push({key, i}); // cerr << key << endl; if (l <= key and key <= u) { // ans found; ans.push_back(i); key -= w[i]; while (key != 0) { ans.push_back(m[key]); key -= w[m[key]]; } return ans; } } while(!pre.empty()) { m[pre.front().first] = pre.front().second; pre.pop(); } } return vector<int>(0); }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:8:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < w.size(); i++) s.push_back({w[i], 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...