Submission #1219976

#TimeUsernameProblemLanguageResultExecution timeMemory
1219976brito.joaoKnapsack (NOI18_knapsack)C++20
Compilation error
0 ms0 KiB
#define pb push_back #define mp make_pair #define fi first #define se second #define all(v) v.begin(), v.end() #define rep(i, a, b) for(int i = a; i < b; ++i) void solve() { int S, N; cin >> S >> N; vector<vector<pair<int, int>>> items(S+1); for(int i = 0; i < N; ++i){ int v, w, k; cin >> v >> w >> k; if(w <= S) items[w].push_back({v, k}); } auto st = [&](pii& a, pii& b) -> bool{ if(a.fi != b.fi) return a.fi > b.fi; return a.se > b.se; }; for(int i = 1; i <= S; ++i) sort(items[i].begin(), items[i].end(), st); vector<pair<int, int>> item; // in item store the following : wt, price for(int i = 1; i <= S; ++i){ int id = 0; int itmct = S / i; while(id < (int)items[i].size() && itmct > 0){ auto [v, k] = items[i][id]; int use = min(k, itmct); for(int j = 0; j < use; ++j) item.pb({i, v}); itmct -= use; id++; } } vector<int> dp(S+1, 0); for(auto& [wt, val] : item) { for(int w = S; w >= wt; --w) { dp[w] = max(dp[w], val + dp[w - wt]); } } cout << dp[S] << endl; } int main() { fast; int t = 1; while(t--) { solve(); } return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:10:5: error: 'cin' was not declared in this scope
   10 |     cin >> S >> N;
      |     ^~~
knapsack.cpp:11:19: error: 'pair' was not declared in this scope
   11 |     vector<vector<pair<int, int>>> items(S+1);
      |                   ^~~~
knapsack.cpp:11:12: error: 'vector' was not declared in this scope
   11 |     vector<vector<pair<int, int>>> items(S+1);
      |            ^~~~~~
knapsack.cpp:11:24: error: expected primary-expression before 'int'
   11 |     vector<vector<pair<int, int>>> items(S+1);
      |                        ^~~
knapsack.cpp:16:13: error: 'items' was not declared in this scope
   16 |             items[w].push_back({v, k});
      |             ^~~~~
knapsack.cpp:19:19: error: 'pii' has not been declared
   19 |     auto st = [&](pii& a, pii& b) -> bool{
      |                   ^~~
knapsack.cpp:19:27: error: 'pii' has not been declared
   19 |     auto st = [&](pii& a, pii& b) -> bool{
      |                           ^~~
knapsack.cpp: In lambda function:
knapsack.cpp:3:12: error: request for member 'first' in 'a', which is of non-class type 'int'
    3 | #define fi first
      |            ^~~~~
knapsack.cpp:20:14: note: in expansion of macro 'fi'
   20 |         if(a.fi != b.fi)
      |              ^~
knapsack.cpp:3:12: error: request for member 'first' in 'b', which is of non-class type 'int'
    3 | #define fi first
      |            ^~~~~
knapsack.cpp:20:22: note: in expansion of macro 'fi'
   20 |         if(a.fi != b.fi)
      |                      ^~
knapsack.cpp:3:12: error: request for member 'first' in 'a', which is of non-class type 'int'
    3 | #define fi first
      |            ^~~~~
knapsack.cpp:21:22: note: in expansion of macro 'fi'
   21 |             return a.fi > b.fi;
      |                      ^~
knapsack.cpp:3:12: error: request for member 'first' in 'b', which is of non-class type 'int'
    3 | #define fi first
      |            ^~~~~
knapsack.cpp:21:29: note: in expansion of macro 'fi'
   21 |             return a.fi > b.fi;
      |                             ^~
knapsack.cpp:4:12: error: request for member 'second' in 'a', which is of non-class type 'int'
    4 | #define se second
      |            ^~~~~~
knapsack.cpp:22:18: note: in expansion of macro 'se'
   22 |         return a.se > b.se;
      |                  ^~
knapsack.cpp:4:12: error: request for member 'second' in 'b', which is of non-class type 'int'
    4 | #define se second
      |            ^~~~~~
knapsack.cpp:22:25: note: in expansion of macro 'se'
   22 |         return a.se > b.se;
      |                         ^~
knapsack.cpp: In function 'void solve()':
knapsack.cpp:26:14: error: 'items' was not declared in this scope
   26 |         sort(items[i].begin(), items[i].end(), st);
      |              ^~~~~
knapsack.cpp:26:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   26 |         sort(items[i].begin(), items[i].end(), st);
      |         ^~~~
      |         short
knapsack.cpp:28:17: error: expected primary-expression before 'int'
   28 |     vector<pair<int, int>> item;
      |                 ^~~
knapsack.cpp:34:25: error: 'items' was not declared in this scope
   34 |         while(id < (int)items[i].size() && itmct > 0){
      |                         ^~~~~
knapsack.cpp:36:23: error: 'min' was not declared in this scope
   36 |             int use = min(k, itmct);
      |                       ^~~
knapsack.cpp:38:17: error: 'item' was not declared in this scope
   38 |                 item.pb({i, v});
      |                 ^~~~
knapsack.cpp:44:12: error: expected primary-expression before 'int'
   44 |     vector<int> dp(S+1, 0);
      |            ^~~
knapsack.cpp:46:27: error: 'item' was not declared in this scope
   46 |     for(auto& [wt, val] : item) {
      |                           ^~~~
knapsack.cpp:48:13: error: 'dp' was not declared in this scope; did you mean 'mp'?
   48 |             dp[w] = max(dp[w], val + dp[w - wt]);
      |             ^~
      |             mp
knapsack.cpp:48:21: error: 'max' was not declared in this scope
   48 |             dp[w] = max(dp[w], val + dp[w - wt]);
      |                     ^~~
knapsack.cpp:51:5: error: 'cout' was not declared in this scope
   51 |     cout << dp[S] << endl;
      |     ^~~~
knapsack.cpp:51:13: error: 'dp' was not declared in this scope; did you mean 'mp'?
   51 |     cout << dp[S] << endl;
      |             ^~
      |             mp
knapsack.cpp:51:22: error: 'endl' was not declared in this scope
   51 |     cout << dp[S] << endl;
      |                      ^~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:55:5: error: 'fast' was not declared in this scope
   55 |     fast;
      |     ^~~~