Submission #527001

#TimeUsernameProblemLanguageResultExecution timeMemory
527001lcs147Detecting Molecules (IOI16_molecules)C++98
Compilation error
0 ms0 KiB
// #include"molecules.h" #include<bits/stdc++.h> using namespace std; vector<int>find_subset(int l, int r, vector<int> w) { if(l > r) return {}; vector<int>id(w.size()); iota(id.begin(), id.end(), 0); sort(id.begin(), id.end(), [&](int a, int b){ return w[a] < w[b]; }); while(id.size() && w[id.back()] > r) id.pop_back(); int sum = 0; vector<int>has_sum(r+1, -1); int en = -1; while(1) { if(sum != 0) { while(sum <= r && has_sum[sum]==-1) sum++; } if(sum > r) return {}; if(sum >= l) { en = sum; break; } for(int i = has_sum[sum]+1; i<id.size(); i++) { int nsum = sum + w[id[i]]; if(nsum > r) break; has_sum[nsum] = i; } sum++; } sum = en; vector<int>res; while(sum > 0) { int rid = id[has_sum[sum]]; res.push_back(rid); sum -= w[rid]; } sort(res.begin(), res.end()); return res; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); #define endl '\n' int n, l, r; cin >> n >> l >> r; vector<int>w(n); for(int i=0; i<n; i++) { cin >> w[i]; } auto res = find_subset(l, r, w); for(int x:res) cout << x << " "; cout << endl; return 0; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:28:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for(int i = has_sum[sum]+1; i<id.size(); i++) {
      |                                     ~^~~~~~~~~~
/usr/bin/ld: /tmp/ccFMqYJx.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccAuNRRy.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status