Submission #309457

# Submission time Handle Problem Language Result Execution time Memory
309457 2020-10-03T14:04:30 Z cig32 Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include "molecules.h"

#define ll long long
std::vector<int> find_subset(int l,int u,std::vector<int>x){
  ll n=x.size();
    pair<ll,ll> w[n];
    bool used[n];
    ll tot_sum=0;
    for(int i=0;i<n;i++)w[i].first=x[i];
    for(int i=0;i<n;i++)w[i].second=i;
    for(int i=0;i<n;i++)tot_sum+=w[i].first;
    for(int i=0;i<n;i++)used[i]=false;
    sort(w,w+n);
    ll curr_sum=0, pt=0, nani=0;
    for(int i=0;i<n;i++){
        curr_sum+=w[i].first;
        if(u<curr_sum){
            curr_sum-=w[i].first;
            pt=i;
            break;
        }
        used[i]=true;
        nani++;
        if(l<=curr_sum&&curr_sum<=u){
          vector<int>v;
            for(int j=0;j<n;j++){
                if(used[j])v.push_back(w[j].second);
            }
            return v;
        }
    }
    for(int i=0;i<min(n-pt,pt);i++){
        curr_sum-=w[i].first;
        used[i]=false;
        curr_sum+=w[n-i-1].first;
        used[n-i-1]=true;
        if(l<=curr_sum&&curr_sum<=u){
            break;
        }
    }
    if(l<=curr_sum&&curr_sum<=u){
        vector<int>v;
        for(int i=0;i<n;i++){
            if(used[i])v.push_back(w[i].second);
   
        }
      return v;
    }
    else{
        vector<int>v;
      return v;
    }
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:6:5: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
    6 |     pair<ll,ll> w[n];
      |     ^~~~
      |     std::pair
In file included from /usr/include/c++/9/bits/stl_algobase.h:64,
                 from /usr/include/c++/9/vector:60,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_pair.h:208:12: note: 'std::pair' declared here
  208 |     struct pair
      |            ^~~~
molecules.cpp:3:12: error: expected primary-expression before 'long'
    3 | #define ll long long
      |            ^~~~
molecules.cpp:6:10: note: in expansion of macro 'll'
    6 |     pair<ll,ll> w[n];
      |          ^~
molecules.cpp:9:25: error: 'w' was not declared in this scope
    9 |     for(int i=0;i<n;i++)w[i].first=x[i];
      |                         ^
molecules.cpp:10:25: error: 'w' was not declared in this scope
   10 |     for(int i=0;i<n;i++)w[i].second=i;
      |                         ^
molecules.cpp:11:34: error: 'w' was not declared in this scope
   11 |     for(int i=0;i<n;i++)tot_sum+=w[i].first;
      |                                  ^
molecules.cpp:13:10: error: 'w' was not declared in this scope
   13 |     sort(w,w+n);
      |          ^
molecules.cpp:13:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   13 |     sort(w,w+n);
      |     ^~~~
      |     short
molecules.cpp:25:11: error: 'vector' was not declared in this scope; did you mean 'std::vector'?
   25 |           vector<int>v;
      |           ^~~~~~
      |           std::vector
In file included from /usr/include/c++/9/vector:67,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:386:11: note: 'std::vector' declared here
  386 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
molecules.cpp:25:18: error: expected primary-expression before 'int'
   25 |           vector<int>v;
      |                  ^~~
molecules.cpp:27:28: error: 'v' was not declared in this scope
   27 |                 if(used[j])v.push_back(w[j].second);
      |                            ^
molecules.cpp:29:20: error: 'v' was not declared in this scope
   29 |             return v;
      |                    ^
molecules.cpp:32:19: error: 'min' was not declared in this scope; did you mean 'std::min'?
   32 |     for(int i=0;i<min(n-pt,pt);i++){
      |                   ^~~
      |                   std::min
In file included from /usr/include/c++/9/vector:60,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:246:5: note: 'std::min' declared here
  246 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
molecules.cpp:42:9: error: 'vector' was not declared in this scope; did you mean 'std::vector'?
   42 |         vector<int>v;
      |         ^~~~~~
      |         std::vector
In file included from /usr/include/c++/9/vector:67,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:386:11: note: 'std::vector' declared here
  386 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
molecules.cpp:42:16: error: expected primary-expression before 'int'
   42 |         vector<int>v;
      |                ^~~
molecules.cpp:44:24: error: 'v' was not declared in this scope
   44 |             if(used[i])v.push_back(w[i].second);
      |                        ^
molecules.cpp:47:14: error: 'v' was not declared in this scope
   47 |       return v;
      |              ^
molecules.cpp:50:9: error: 'vector' was not declared in this scope; did you mean 'std::vector'?
   50 |         vector<int>v;
      |         ^~~~~~
      |         std::vector
In file included from /usr/include/c++/9/vector:67,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:386:11: note: 'std::vector' declared here
  386 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
molecules.cpp:50:16: error: expected primary-expression before 'int'
   50 |         vector<int>v;
      |                ^~~
molecules.cpp:51:14: error: 'v' was not declared in this scope
   51 |       return v;
      |              ^