제출 #706760

#제출 시각아이디문제언어결과실행 시간메모리
706760Yell0Detecting Molecules (IOI16_molecules)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; typedef long long ll; int find_subset(int l,int u,int[] w,int n,int[] result) { vector<pii> a; for(int i=0;i<n;++i) a.push_back({w[i],i}); sort(a.begin(),a.end()); int i=0,j=0; ll sum=0; for(;i<n;++i) { sum+=a[i].first; if(sum>=l) break; } if(sum<l) return 0; for(;j<=i;++j) { sum-=a[j].first; if(sum<=u) break; } if(sum>u) return 0; for(int x=0;x<=i-j;++x) result[x]=a[x+j].second; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

molecules.cpp:7:35: error: expected ',' or '...' before 'w'
    7 | int find_subset(int l,int u,int[] w,int n,int[] result) {
      |                                   ^
molecules.cpp: In function 'int find_subset(int, int, int*)':
molecules.cpp:9:17: error: 'n' was not declared in this scope
    9 |   for(int i=0;i<n;++i) a.push_back({w[i],i});
      |                 ^
molecules.cpp:9:37: error: 'w' was not declared in this scope
    9 |   for(int i=0;i<n;++i) a.push_back({w[i],i});
      |                                     ^
molecules.cpp:9:44: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
    9 |   for(int i=0;i<n;++i) a.push_back({w[i],i});
      |                                            ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from molecules.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
molecules.cpp:13:10: error: 'n' was not declared in this scope
   13 |   for(;i<n;++i) {
      |          ^
molecules.cpp:23:27: error: 'result' was not declared in this scope
   23 |   for(int x=0;x<=i-j;++x) result[x]=a[x+j].second;
      |                           ^~~~~~