제출 #997085

#제출 시각아이디문제언어결과실행 시간메모리
997085codefoxDetecting Molecules (IOI16_molecules)C++14
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; #define pii pair<int, int> int* find_subset(int l, int u, int[] w) { vector<pii> nums; for (int i = 0; i < n; i++) nums.push_back({w[i], i}); sort(nums.begin(), nums.end()); int left=0, right=0; long long sum = 0; while (sum <= l) { sum += nums[right].first; right++; } right--; sum -= nums[right].first; while (sum <= u) { sum += nums[right].first; right++; sum -= nums[left].first; left++; } right--; sum -= nums[right].first; left--; sum -= nums[left].first; if (sum >= l) {ac int ans[right-left]; for (int i = left; i < right; i++) { ans[i-left] = nums[i].second; } return ans; } else { int ans[0]; return ans; } }

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

molecules.cpp:7:38: error: expected ',' or '...' before 'w'
    7 | int* find_subset(int l, int u, int[] w)
      |                                      ^
molecules.cpp: In function 'int* find_subset(int, int, int*)':
molecules.cpp:10:22: error: 'n' was not declared in this scope
   10 |  for (int i = 0; i < n; i++) nums.push_back({w[i], i});
      |                      ^
molecules.cpp:10:46: error: 'w' was not declared in this scope
   10 |  for (int i = 0; i < n; i++) nums.push_back({w[i], i});
      |                                              ^
molecules.cpp:10:54: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
   10 |  for (int i = 0; i < n; i++) nums.push_back({w[i], i});
      |                                                      ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 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:34:3: error: 'ac' was not declared in this scope
   34 |  {ac
      |   ^~
molecules.cpp:38:4: error: 'ans' was not declared in this scope; did you mean 'abs'?
   38 |    ans[i-left] = nums[i].second;
      |    ^~~
      |    abs
molecules.cpp:40:10: error: 'ans' was not declared in this scope; did you mean 'abs'?
   40 |   return ans;
      |          ^~~
      |          abs
molecules.cpp:45:10: warning: address of local variable 'ans' returned [-Wreturn-local-addr]
   45 |   return ans;
      |          ^~~
molecules.cpp:44:7: note: declared here
   44 |   int ans[0];
      |       ^~~