답안 #284599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284599 2020-08-27T17:20:41 Z triplem5ds Detecting Molecules (IOI16_molecules) C++14
컴파일 오류
0 ms 0 KB
#include "molecules.h"
#include "bits/stdc++.h"
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    vector<int> v;
    for(int i = 0; i < w.size(); i++)v.push_back(i);
    sort(v.begin(),v.end(), [&](int x, int y){return w[x] < w[y]});
    if(accumulate(w.begin(),w.end(),0ll) < l || w[v[0]] > u)return vector<int>();
    vector<int> ret;
    int sum = 0;
    for(int j = 0; sum < l; j++){
      sum += w[v[j]];
      ret.push_back(v[j] + 1);
    }
    return ret;
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:4:5: error: 'vector' was not declared in this scope; did you mean 'std::vector'?
    4 |     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:4:12: error: expected primary-expression before 'int'
    4 |     vector<int> v;
      |            ^~~
molecules.cpp:5:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 |     for(int i = 0; i < w.size(); i++)v.push_back(i);
      |                    ~~^~~~~~~~~~
molecules.cpp:5:38: error: 'v' was not declared in this scope
    5 |     for(int i = 0; i < w.size(); i++)v.push_back(i);
      |                                      ^
molecules.cpp:6:10: error: 'v' was not declared in this scope
    6 |     sort(v.begin(),v.end(), [&](int x, int y){return w[x] < w[y]});
      |          ^
molecules.cpp: In lambda function:
molecules.cpp:6:65: error: expected ';' before '}' token
    6 |     sort(v.begin(),v.end(), [&](int x, int y){return w[x] < w[y]});
      |                                                                 ^
      |                                                                 ;
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:6:5: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
    6 |     sort(v.begin(),v.end(), [&](int x, int y){return w[x] < w[y]});
      |     ^~~~
      |     std::sort
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from molecules.cpp:2:
/usr/include/c++/9/bits/stl_algo.h:4887:5: note: 'std::sort' declared here
 4887 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
molecules.cpp:7:75: error: expected primary-expression before 'int'
    7 |     if(accumulate(w.begin(),w.end(),0ll) < l || w[v[0]] > u)return vector<int>();
      |                                                                           ^~~
molecules.cpp:7:75: error: expected ';' before 'int'
    7 |     if(accumulate(w.begin(),w.end(),0ll) < l || w[v[0]] > u)return vector<int>();
      |                                                                           ^~~
      |                                                                           ;
molecules.cpp:7:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    7 |     if(accumulate(w.begin(),w.end(),0ll) < l || w[v[0]] > u)return vector<int>();
      |     ^~
molecules.cpp:7:75: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
    7 |     if(accumulate(w.begin(),w.end(),0ll) < l || w[v[0]] > u)return vector<int>();
      |                                                                           ^~~
molecules.cpp:7:78: error: expected unqualified-id before '>' token
    7 |     if(accumulate(w.begin(),w.end(),0ll) < l || w[v[0]] > u)return vector<int>();
      |                                                                              ^
molecules.cpp:8:12: error: expected primary-expression before 'int'
    8 |     vector<int> ret;
      |            ^~~
molecules.cpp:12:7: error: 'ret' was not declared in this scope
   12 |       ret.push_back(v[j] + 1);
      |       ^~~
molecules.cpp:14:12: error: 'ret' was not declared in this scope
   14 |     return ret;
      |            ^~~