# | 제출 시각UTC-0 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
967846 | 2024-04-23 02:07:00 | hippo123 | Knapsack (NOI18_knapsack) | C++17 | 컴파일 에러 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct data{
int v, w, k;
double r;
};
bool comp(data a, data b){
if(a.r==b.r) return a.w<b.w;
return a.r>b.r;
}
int main(){
int s, n; cin>>s>>n;
vector<data> d(n);
for (int i=0; i<n; i++) {
cin>>d[i].v>>d[i].w>>d[i].k;
d[i].r=double(d[i].v)/d[i].w;
}
sort(d.begin(), d.end(), comp);
vector<ll> dp(s+1, -1);
dp[0]=0;
for (int i=0; i<n; i++){
for (int x=s; x>=0; x--){
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp:10:11: error: reference to 'data' is ambiguous 10 | bool comp(data a, data b){ | ^~~~ In file included from /usr/include/c++/10/string:54, from /usr/include/c++/10/bits/locale_classes.h:40, from /usr/include/c++/10/bits/ios_base.h:41, from /usr/include/c++/10/ios:42, from /usr/include/c++/10/istream:38, from /usr/include/c++/10/sstream:38, from /usr/include/c++/10/complex:45, from /usr/include/c++/10/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54, from knapsack.cpp:1: /usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)' 319 | data(initializer_list<_Tp> __il) noexcept | ^~~~ /usr/include/c++/10/bits/range_access.h:310:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])' 310 | data(_Tp (&__array)[_Nm]) noexcept | ^~~~ /usr/include/c++/10/bits/range_access.h:300:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)' 300 | data(const _Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ /usr/include/c++/10/bits/range_access.h:290:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)' 290 | data(_Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ knapsack.cpp:5:8: note: 'struct data' 5 | struct data{ | ^~~~ knapsack.cpp:10:19: error: reference to 'data' is ambiguous 10 | bool comp(data a, data b){ | ^~~~ In file included from /usr/include/c++/10/string:54, from /usr/include/c++/10/bits/locale_classes.h:40, from /usr/include/c++/10/bits/ios_base.h:41, from /usr/include/c++/10/ios:42, from /usr/include/c++/10/istream:38, from /usr/include/c++/10/sstream:38, from /usr/include/c++/10/complex:45, from /usr/include/c++/10/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54, from knapsack.cpp:1: /usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)' 319 | data(initializer_list<_Tp> __il) noexcept | ^~~~ /usr/include/c++/10/bits/range_access.h:310:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])' 310 | data(_Tp (&__array)[_Nm]) noexcept | ^~~~ /usr/include/c++/10/bits/range_access.h:300:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)' 300 | data(const _Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ /usr/include/c++/10/bits/range_access.h:290:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)' 290 | data(_Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ knapsack.cpp:5:8: note: 'struct data' 5 | struct data{ | ^~~~ knapsack.cpp:10:25: error: expression list treated as compound expression in initializer [-fpermissive] 10 | bool comp(data a, data b){ | ^ knapsack.cpp: In function 'int main()': knapsack.cpp:18:13: error: template argument 1 is invalid 18 | vector<data> d(n); | ^ knapsack.cpp:18:13: error: template argument 2 is invalid knapsack.cpp:21:9: error: invalid types 'int[int]' for array subscript 21 | cin>>d[i].v>>d[i].w>>d[i].k; | ^ knapsack.cpp:21:17: error: invalid types 'int[int]' for array subscript 21 | cin>>d[i].v>>d[i].w>>d[i].k; | ^ knapsack.cpp:21:25: error: invalid types 'int[int]' for array subscript 21 | cin>>d[i].v>>d[i].w>>d[i].k; | ^ knapsack.cpp:22:4: error: invalid types 'int[int]' for array subscript 22 | d[i].r=double(d[i].v)/d[i].w; | ^ knapsack.cpp:22:18: error: invalid types 'int[int]' for array subscript 22 | d[i].r=double(d[i].v)/d[i].w; | ^ knapsack.cpp:22:26: error: invalid types 'int[int]' for array subscript 22 | d[i].r=double(d[i].v)/d[i].w; | ^ knapsack.cpp:24:9: error: request for member 'begin' in 'd', which is of non-class type 'int' 24 | sort(d.begin(), d.end(), comp); | ^~~~~ knapsack.cpp:24:20: error: request for member 'end' in 'd', which is of non-class type 'int' 24 | sort(d.begin(), d.end(), comp); | ^~~ knapsack.cpp:32:22: error: invalid types 'int[int]' for array subscript 32 | for (int j=0; j<d[i].k && x+(j+1)*d[i].w<=s; j++){ | ^ knapsack.cpp:32:40: error: invalid types 'int[int]' for array subscript 32 | for (int j=0; j<d[i].k && x+(j+1)*d[i].w<=s; j++){ | ^ knapsack.cpp:33:18: error: invalid types 'int[int]' for array subscript 33 | dp[x+(j+1)*d[i].w]=max(dp[x]+(j+1)*d[i].v, dp[x+(j+1)*d[i].w]); | ^ knapsack.cpp:33:42: error: invalid types 'int[int]' for array subscript 33 | dp[x+(j+1)*d[i].w]=max(dp[x]+(j+1)*d[i].v, dp[x+(j+1)*d[i].w]); | ^ knapsack.cpp:33:61: error: invalid types 'int[int]' for array subscript 33 | dp[x+(j+1)*d[i].w]=max(dp[x]+(j+1)*d[i].v, dp[x+(j+1)*d[i].w]); | ^