Submission #1132190

#TimeUsernameProblemLanguageResultExecution timeMemory
1132190lopkusDetecting Molecules (IOI16_molecules)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h> #include "molecules.h" using namespace std; std::vector<int> find_subset(int l, int u, std::vector<int> w) { sort(w.begin(), w.end()); int n = w.size(); for(int i = 0; i < n; i++) { if(w[i] >= l && w[i] <= u) { return {i}; } } int idx = - 1; for(int i = 0; i < n; i++) { if(w[i] < l) { idx = i; } } if(idx == - 1) { return {}; } set<int> s; s.insert(w[idx]); for(int i = idx; i >= 0; i--) { if(u - l >= w[idx] - w[i]) { s.insert(w[i]); } } vector<int> ans; while(l > 0) { auto it = s.lower_bound(l); if(it != s.end() && *it <= u) { ans.push_back(*it); l -= *it; u -= *it; s.erase(it); continue; } it--; if(it != s.end()) { ans.push_back(*it); l -= *it; u -= *it; s.erase(it); } else { return {}; } } return ans; }

Compilation message (stderr)

molecules.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...