Submission #1023679

#TimeUsernameProblemLanguageResultExecution timeMemory
1023679vjudge1Knapsack (NOI18_knapsack)C++17
49 / 100
1099 ms348 KiB
#include <bits/stdc++.h> #include <vector> using namespace std; #define int long long #define ff first #define ss second #define tobit(n) bitset<20>(n) //выводит 20 элементов в битовую систему #define all(v) (v).begin(), (v).end() #define rtt(v, k) rotate(v.begin(), v.begin() + k, v.end()); //move k elements back const int MOD = 1e9 + 7; int binpownm(int n, int m){ if(m == 1) return n; if(m % 2 == 0){ int t = binpownm(n, m / 2); return t * t; } else return binpownm(n, m - 1) * n; } bool sortt(pair<int, double> a, pair<int, double> b){ return a.ss < b.ss; } struct sturc_t { int ff_, ss_, tt_; }; int knaps(vector<int>& cur, vector<int>& cst, int S){ vector<vector<int>> dp(S + 1, vector<int> (cur.size() + 1, 0)); for(int j = 1; j <= cur.size(); j++){ for(int w = 1; w <= S; w++){ if(cur[j-1] <= w){ dp[w][j] = max(dp[w][j - 1], dp[w - cur[j - 1]][j - 1] + cst[j - 1]); } else dp[w][j] = dp[w][j - 1]; } } return dp[S][cur.size()]; } int knapsack2(vector<sturc_t>& v, int S){ vector<int> dp(S + 1, 0); for(auto& to : v){ for(int q = 0; q < to.tt_; q++){ for(int w = S; w >= to.ss_; w--){ dp[w] = max(dp[w], dp[w - to.ss_] + to.ff_); } } } return dp[S]; } signed main(){ int n, s; cin >> n >> s; vector<sturc_t> v(s); vector<int> res, cst; for(int i = 0; i < s; i++){ cin >> v[i].ff_ >> v[i].ss_ >> v[i].tt_; cst.emplace_back(v[i].ff_); res.emplace_back(v[i].ss_); } if(s == 1){ int answer = 0; for(int k = v[0].tt_; k >= 0; k--){ if(v[0].ss_ * k <= n){ answer = v[0].ff_ * k; break; } } cout << answer; return 0; } cout << knapsack2(v, n); } // NEED TO FAST CIN && COUT // const int fastIO = [](){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }();

Compilation message (stderr)

knapsack.cpp: In function 'long long int knaps(std::vector<long long int>&, std::vector<long long int>&, long long int)':
knapsack.cpp:25:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int j = 1; j <= cur.size(); j++){
      |                    ~~^~~~~~~~~~~~~
#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...