Submission #970465

#TimeUsernameProblemLanguageResultExecution timeMemory
970465v_mateiKnapsack (NOI18_knapsack)C++17
73 / 100
1004 ms1580 KiB
#pragma GCC optimize(" unroll-loops") #include<bits/stdc++.h> #include <vector> #define ll long long #define ull unsigned long long #define pii std::pair<int, int> #define NMAX 100'007 #define SMAX 2007 int n, s; int v[NMAX], w[NMAX], k[NMAX]; std::vector<int> dp[2]; void citire(){ std::cin >> s >> n; for(int i = 1; i <= n; i++) std::cin >> v[i] >> w[i] >> k[i]; dp[0].resize(s + 1); dp[1].resize(s + 1); } int main(){ citire(); for(int i = 1; i <= n; i++){ for(int j = 0; j <= s; j++){ dp[1][j] = dp[0][j]; for(int x = 0; j - w[i]*x >= 0 && x <= k[i]; x++){ dp[1][j] = std::max(dp[1][j], dp[0][j - x*w[i]] + x*v[i]); } } dp[0] = dp[1]; dp[1].clear(); dp[1].resize(s + 1); } std::cout << dp[0][s]; return 0; }

Compilation message (stderr)

knapsack.cpp:1:37: warning: bad option '-f unroll-loops' to pragma 'optimize' [-Wpragmas]
    1 | #pragma GCC optimize(" unroll-loops")
      |                                     ^
knapsack.cpp:16:13: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
   16 | void citire(){
      |             ^
knapsack.cpp:24:10: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
   24 | int main(){
      |          ^
#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...