제출 #1129146

#제출 시각아이디문제언어결과실행 시간메모리
1129146idkfrKnapsack (NOI18_knapsack)C++20
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; int main() { int n, W; cin >> W >> n; vector<ll> dp(W + 1, 0); for (int i = 0; i < n; ++i) { int wi, vi, ai; cin >> vi >> wi >> ai; for (int k = 1; ai > 0; k *= 2) { int num = min(k, ai); ai -= num; int weight = num * wi; int value = num * vi; for (int j = W; j >= weight; --j) { dp[j] = max(dp[j], dp[j - weight] + value); } } } cout << dp[W] << endl; return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:9:12: error: 'll' was not declared in this scope
    9 |     vector<ll> dp(W + 1, 0);
      |            ^~
knapsack.cpp:9:14: error: template argument 1 is invalid
    9 |     vector<ll> dp(W + 1, 0);
      |              ^
knapsack.cpp:9:14: error: template argument 2 is invalid
knapsack.cpp:9:27: error: expression list treated as compound expression in initializer [-fpermissive]
    9 |     vector<ll> dp(W + 1, 0);
      |                           ^
knapsack.cpp:22:19: error: invalid types 'int[int]' for array subscript
   22 |                 dp[j] = max(dp[j], dp[j - weight] + value);
      |                   ^
knapsack.cpp:22:31: error: invalid types 'int[int]' for array subscript
   22 |                 dp[j] = max(dp[j], dp[j - weight] + value);
      |                               ^
knapsack.cpp:22:38: error: invalid types 'int[int]' for array subscript
   22 |                 dp[j] = max(dp[j], dp[j - weight] + value);
      |                                      ^
knapsack.cpp:27:15: error: invalid types 'int[int]' for array subscript
   27 |     cout << dp[W] << endl;
      |               ^