제출 #1092566

#제출 시각아이디문제언어결과실행 시간메모리
1092566AryanPadarthiKnapsack (NOI18_knapsack)C++11
0 / 100
322 ms262144 KiB
// Source: https://usaco.guide/general/io #include <bits/stdc++.h> using namespace std; int main() { int w; int n; int mval=0; int bob; cin >> w >> n; vector<int> points(n); vector<int> weight(n); vector<int> count(n); vector<int> useful; for (int i = 0; i < n; i++){ cin >> points[i] >> weight[i] >> count[i]; } vector<int> dp(w+1,0); //dp[0]=1; for (int i = 0; i < n; i++){ for (int j = 0; j < count[i]; j++){ bob= useful.size(); for (int k = useful.size()-1; k >-1 ; k--){ if (dp[useful[k]] > 0){ if (useful[k]+weight[i]<dp.size()){ dp[useful[k]+weight[i]] = max(dp[useful[k]+weight[i]],dp[useful[k]] + points[i]); useful.push_back(useful[k]+weight[i]); } } } if (j==0){ dp[weight[i]] = max(dp[weight[i]],points[i]); useful.push_back(weight[i]); } } } for (int i = 0; i < dp.size(); i++){ if (dp[i]>mval){ mval = dp[i]; } } cout << mval; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:31:29: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |      if (useful[k]+weight[i]<dp.size()){
knapsack.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for (int i = 0; i < dp.size(); i++){
      |                  ~~^~~~~~~~~~~
knapsack.cpp:11:6: warning: variable 'bob' set but not used [-Wunused-but-set-variable]
   11 |  int bob;
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...