Submission #474466

#TimeUsernameProblemLanguageResultExecution timeMemory
474466GumloihacknaoDetecting Molecules (IOI16_molecules)C++14
Compilation error
0 ms0 KiB
#include <iostream> #include <algorithm> #include <fstream> #include <vector> using namespace std; int n, l, u, m, sum; bool result = false; vector<int> a,d,c,e; void nhap() { ifstream f; f.open("2016.inp"); f >> n >> l >> u; for ( int i = 0; i < n; i++) { f >> m; sum += m; a.push_back(m); } f.close(); } void xl() { for(int i = 0; i <= sum; i++) { d.push_back(0); c.push_back(0); } d[0] = 1; for (int i = 0; i < n; i++) { for (int j = sum; j >= a[i]; j--) { if (d[j] == 0 && d[j-a[i]] == 1) { d[j] = 1; c[j] = i; } } } } void xuat() { int m = 0; ofstream f; f.open("2016.out"); for ( int i = l; i <= u; i++) { if (d[i] == 1) result = true; { m = i; while ( m - a[c[m]] >= 0) { e.push_back(c[m]); m -= a[c[m]]; } break; } } if (result) { for ( int i = 0; i < e.size(); i++) { f << e[i] << " "; } } else { f << 0; } f.close(); } int main() { nhap(); xl(); xuat(); return 0; }

Compilation message (stderr)

molecules.cpp: In function 'void xuat()':
molecules.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |   for ( int i = 0; i < e.size(); i++)
      |                    ~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccNglvHE.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccsaw9QD.o:molecules.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccNglvHE.o: in function `main':
grader.cpp:(.text.startup+0x18d): undefined reference to `find_subset(int, int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status