Submission #568378

#TimeUsernameProblemLanguageResultExecution timeMemory
568378Trisanu_DasDetecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "molecules.h" using namespace std; #define ff first #define ss second int find_subset(int l, int u, vector<int> w){ vector<pair<int, int> > w_sort; int n = w.size(); for(int i = 0, i < n; i++) w_sort.push_back({w[i], i}); sort(w_sort.begin(), w_sort.end()); int sum = 0; vector<int> ans; for(int i = 0; i < n; i++){ sum += w_sort[i].ff; ans.push_back(w_sort[i].ss); if(l <= sum && sum <= u) return ans; } ans.clear(); if(sum > l || w_sort[0].ff > r) return ans; int last = 0; sum = 0; for(int i = 0; i < n; i++) { if(sum + w_sort[i].ff > l) break; sum += w_sort[i].ff; last = i; } int len = last + 1; for(int i = last + 1; i < n; i++) { sum -= w_sort[i - len].ff; sum += w_sort[i].ff; if(sum >= l) { for(int j = i - len + 1; j <= i; j++) ans.push_back(w_sort[j].ss); return ans; } } return ans; }

Compilation message (stderr)

molecules.cpp:7:5: error: ambiguating new declaration of 'int find_subset(int, int, std::vector<int>)'
    7 | int find_subset(int l, int u, vector<int> w){
      |     ^~~~~~~~~~~
In file included from molecules.cpp:2:
molecules.h:5:18: note: old declaration 'std::vector<int> find_subset(int, int, std::vector<int>)'
    5 | std::vector<int> find_subset(int l, int u, std::vector<int> w);
      |                  ^~~~~~~~~~~
molecules.cpp: In function 'int find_subset(int, int, std::vector<int>)':
molecules.cpp:10:19: error: expected ';' before '<' token
   10 |   for(int i = 0, i < n; i++) w_sort.push_back({w[i], i});
      |                   ^~
      |                   ;
molecules.cpp:10:20: error: expected primary-expression before '<' token
   10 |   for(int i = 0, i < n; i++) w_sort.push_back({w[i], i});
      |                    ^
molecules.cpp:17:37: error: cannot convert 'std::vector<int>' to 'int' in return
   17 |     if(l <= sum && sum <= u) return ans;
      |                                     ^~~
molecules.cpp:20:32: error: 'r' was not declared in this scope
   20 |   if(sum > l || w_sort[0].ff > r) return ans;
      |                                ^
molecules.cpp:20:42: error: cannot convert 'std::vector<int>' to 'int' in return
   20 |   if(sum > l || w_sort[0].ff > r) return ans;
      |                                          ^~~
molecules.cpp:33:11: error: cannot convert 'std::vector<int>' to 'int' in return
   33 |    return ans;
      |           ^~~
molecules.cpp:36:9: error: cannot convert 'std::vector<int>' to 'int' in return
   36 |  return ans;
      |         ^~~