Submission #1268807

#TimeUsernameProblemLanguageResultExecution timeMemory
1268807bgnbvnbvDetecting Molecules (IOI16_molecules)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; vector<int> find_subset(int l, int u, const vector<int> &w) { int n = w.size(); vector<pair<int,int>> a(n); for(int i = 0; i < n; i++) a[i] = {w[i], i}; sort(a.begin(), a.end()); vector<long long> pref(n+1, 0); for(int i = 0; i < n; i++) pref[i+1] = pref[i] + a[i].first; int j = 0; for(int i = 1; i <= n; i++) { // pref[i] - pref[j] là tổng đoạn [j..i-1] while(j < i && pref[i] - pref[j] > u) j++; if(j < i && pref[i] - pref[j] >= l && pref[i] - pref[j] <= u) { vector<int> res; for(int k = j; k < i; k++) res.push_back(a[k].second); return res; } } return {}; } int main(){ int l = 15, u = 17; vector<int> w = {6,8,8,7}; auto ans = find_subset(l,u,w); if(ans.empty()) cout << "No subset\n"; else{ for(int x: ans) cout << x+1 << " "; // in 1-based cout << "\n"; } }

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
      |         ^~~~
/usr/bin/ld: /tmp/cc9h5tgJ.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccrH06gr.o:molecules.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc9h5tgJ.o: in function `main':
grader.cpp:(.text.startup+0x165): undefined reference to `find_subset(int, int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status