Submission #88625

# Submission time Handle Problem Language Result Execution time Memory
88625 2018-12-07T07:49:24 Z Nucleist Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include "molecules.h"

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    int k = w.size();
    int f = l;
    l=u;
    int n = k;
    vector <int> kk;
    int sum = max(f,l);
    bool subset[k+1][max(f,l)+1];
    for (int i = 0; i <= n; i++)
      subset[i][0] = true;
    for (int i = 1; i <= sum; i++)
      subset[0][i] = false;
    for (int i = 1; i <= n; i++)
     {
       for (int j = 1; j <= sum; j++)
       {
         if(j<w[i-1])
         subset[i][j] = subset[i-1][j];
         if (j >= w[i-1])
           subset[i][j] = subset[i-1][j] ||
                                 subset[i - 1][j-w[i-1]];
       }
     }
     bool ka = false;

     for (int j = min(l,f); j <= max(l,f); j++)
     {
         int kaa=j;
          if(subset[n][j])
          {
              for(int i = n;i>=1;i--)
              {

                  if(subset[i-1][kaa-w[i-1]])
                  {
                    kk.push_back(w[i-1]);
                    kaa -= w[i-1];
                    compteur++;
                    ka=true;
                    if(kaa==0)
                        break;
                  }
              }
          }
          if(ka)
            break;
     }
     cout<<compteur<<'\n';
     for(int i=0;i<compteur;i++)
        cout<<kk[i]<<" ";
    return std::vector<int>kk;
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:8:5: error: 'vector' was not declared in this scope
     vector <int> kk;
     ^~~~~~
molecules.cpp:8:5: note: suggested alternative:
In file included from /usr/include/c++/7/vector:64:0,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:216:11: note:   'std::vector'
     class vector : protected _Vector_base<_Tp, _Alloc>
           ^~~~~~
molecules.cpp:8:13: error: expected primary-expression before 'int'
     vector <int> kk;
             ^~~
molecules.cpp:9:15: error: 'max' was not declared in this scope
     int sum = max(f,l);
               ^~~
molecules.cpp:9:15: note: suggested alternative:
In file included from /usr/include/c++/7/vector:60:0,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   'std::max'
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
molecules.cpp:12:7: error: 'subset' was not declared in this scope
       subset[i][0] = true;
       ^~~~~~
molecules.cpp:14:7: error: 'subset' was not declared in this scope
       subset[0][i] = false;
       ^~~~~~
molecules.cpp:20:10: error: 'subset' was not declared in this scope
          subset[i][j] = subset[i-1][j];
          ^~~~~~
molecules.cpp:22:12: error: 'subset' was not declared in this scope
            subset[i][j] = subset[i-1][j] ||
            ^~~~~~
molecules.cpp:28:19: error: 'min' was not declared in this scope
      for (int j = min(l,f); j <= max(l,f); j++)
                   ^~~
molecules.cpp:28:19: note: suggested alternative:
In file included from /usr/include/c++/7/vector:60:0,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   'std::min'
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
molecules.cpp:31:14: error: 'subset' was not declared in this scope
           if(subset[n][j])
              ^~~~~~
molecules.cpp:38:21: error: 'kk' was not declared in this scope
                     kk.push_back(w[i-1]);
                     ^~
molecules.cpp:38:21: note: suggested alternative: 'ka'
                     kk.push_back(w[i-1]);
                     ^~
                     ka
molecules.cpp:40:21: error: 'compteur' was not declared in this scope
                     compteur++;
                     ^~~~~~~~
molecules.cpp:40:21: note: suggested alternative: 'constexpr'
                     compteur++;
                     ^~~~~~~~
                     constexpr
molecules.cpp:50:6: error: 'cout' was not declared in this scope
      cout<<compteur<<'\n';
      ^~~~
molecules.cpp:50:12: error: 'compteur' was not declared in this scope
      cout<<compteur<<'\n';
            ^~~~~~~~
molecules.cpp:50:12: note: suggested alternative: 'constexpr'
      cout<<compteur<<'\n';
            ^~~~~~~~
            constexpr
molecules.cpp:52:15: error: 'kk' was not declared in this scope
         cout<<kk[i]<<" ";
               ^~
molecules.cpp:52:15: note: suggested alternative: 'ka'
         cout<<kk[i]<<" ";
               ^~
               ka
molecules.cpp:53:28: error: expected primary-expression before 'kk'
     return std::vector<int>kk;
                            ^~
molecules.cpp:53:28: error: expected ';' before 'kk'
molecules.cpp:53:28: error: 'kk' was not declared in this scope
molecules.cpp:53:28: note: suggested alternative: 'ka'
     return std::vector<int>kk;
                            ^~
                            ka