Submission #524054

#TimeUsernameProblemLanguageResultExecution timeMemory
524054shubham20_03Knapsack (NOI18_knapsack)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); #define deb(x) cout<<#x<<'='<<x<<'\n'; #define deb2(x,y) cout<<#x<<'='<<x<<", "<<#y<<'='<<y<<'\n'; #define all(x) (x).begin(), (x).end() #define pii pair<int, int> #define pb push_back #define f first #define s second #define sz(x) (int)(x).size() const long double PI = acos(-1); const int mod = 1e9 + 7, inf = 1e16; const int D = 1e7; int dp[D + 1][2001]; int knapsack(vector<pii>& a, int n, int S) { if (S == 0 or n == 0) return 0; if (dp[n][S] != -1) return dp[n][S]; int ans = knapsack(a, n - 1, S); if (a[n - 1].f <= S) ans = max(ans, knapsack(a, n - 1, S - a[n - 1].f) + a[n - 1].s); return dp[n][S] = ans; } signed main() { fastio // freopen("../input1.txt", "r", stdin); // freopen("../output1.txt", "w", stdout); memset(dp, -1, sizeof(dp)); int S, n; cin >> S >> n; vector<pii> a; for (int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; int cur = 0; while (cur + w <= S and k > 0) { a.pb({w, v}); k--, cur += w; } } n = sz(a); cout << knapsack(a, n, S) << '\n'; return 0; }

Compilation message (stderr)

knapsack.cpp:13:32: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+16' to '2147483647' [-Woverflow]
   13 | const int mod = 1e9 + 7, inf = 1e16;
      |                                ^~~~
/tmp/ccHBei4X.o: in function `main':
knapsack.cpp:(.text.startup+0x47): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
knapsack.cpp:(.text.startup+0x5c): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
knapsack.cpp:(.text.startup+0xc0): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
knapsack.cpp:(.text.startup+0x17e): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
/tmp/ccHBei4X.o: in function `_GLOBAL__sub_I_dp':
knapsack.cpp:(.text.startup+0x1eb): relocation truncated to fit: R_X86_64_PC32 against `.bss'
knapsack.cpp:(.text.startup+0x209): relocation truncated to fit: R_X86_64_PC32 against `.bss'
/usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(vterminate.o): in function `__gnu_cxx::__verbose_terminate_handler()':
(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x1e): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZZN9__gnu_cxx27__verbose_terminate_handlerEvE11terminating'
(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x2b): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZZN9__gnu_cxx27__verbose_terminate_handlerEvE11terminating'
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status