제출 #1198398

#제출 시각아이디문제언어결과실행 시간메모리
1198398andrejikusDetecting Molecules (IOI16_molecules)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> //#include "molecules.h" using namespace std; typedef long long ll; void DBG() { cerr << "]" << endl; } template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); } #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) const int N = 1e4 + 3; vector<int> ww; bool cmp(const int& i, const int& j) { return (ww[i] < ww[j]); } vector<int> find_subset(int l, int u, vector<int> w) { ww = w; vector<int> res(w.size()); iota(res.begin(), res.end(), 0); sort(res.begin(), res.end(), cmp); int suml = 0, sumr = 0; for (int i = 0; i < w.size(); i++) { int rr = w.size()-1-i; suml += w[res[i]], sumr += w[res[rr]]; if (suml <= u && sumr >= l) { vector<int> ans; int t = w.size()-1, p = 0; while (sumr > u && p < rr) { ans.push_back(res[p++]); sumr -= w[res[t--]]; } for (int j = rr; j <= t; j++) ans.push_back(res[j]); sort(ans.begin(), ans.end()); return ans; } } } int main() { int n, l, u; assert(3 == scanf("%d %d %d", &n, &l, &u)); std::vector<int> w(n); for (int i = 0; i < n; i++) assert(1 == scanf("%d", &w[i])); std::vector<int> result = find_subset(l, u, w); printf("%d\n", (int)result.size()); for (int i = 0; i < (int)result.size(); i++) printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]); } /* 4 15 17 6 8 8 7 4 15 16 5 5 6 6 4 10 20 15 17 16 18 */

컴파일 시 표준 에러 (stderr) 메시지

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:40:1: warning: control reaches end of non-void function [-Wreturn-type]
   40 | }
      | ^
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/cc5TG4Hg.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc7WYZoD.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status