Submission #719959

#TimeUsernameProblemLanguageResultExecution timeMemory
719959vinnipuh01Detecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
//#include "molecules.h" #include <bits/stdc++.h> using namespace std; vector <int> v; vector<int> find_subset(int l , int u , vector<int> w) { set <pair<int, int> > st, s; int sum = 0; sort( w.begin(), w.end() ); if ( w.front() > u ) { vector <int> v; return v; } else if ( w.front() <= u && w.front() >= l ) { vector <int> v; v.push_back( 0 ); return v; } for ( int i = 0; i < w.size(); i ++ ) { if ( sum + w[ i ] <= l ) st.insert( { w[ i ], i } ), sum += w[ i ]; else s.insert( { w[i ], i } ); } while ( s.size() && sum < l ) { if ( st.size() ) sum += s.rbegin()->first - st.begin()->first; else sum += s.rbegin()->first; if ( st.size() ) st.erase( st.begin() ); st.insert( *s.rbegin() ); s.erase( --s.end() ); } vector <int> v; v.clear(); if ( sum < l ) return v; for ( auto i : st ) v.push_back( i.second ); return v; } main () { int l, r; cin >> l >> r; int n; cin >> n; int num; for ( int i = 1; i <= n; i ++ ) { cin >> num; v.push_back( num ); } v = find_subset( l, r, v ); for ( auto i : v ) cout << i << " "; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:21:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for ( int i = 0; i < w.size(); i ++ ) {
      |                   ~~^~~~~~~~~~
molecules.cpp: At global scope:
molecules.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main () {
      | ^~~~
/usr/bin/ld: /tmp/ccx7PfcP.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccVpxLBR.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status