제출 #1023809

#제출 시각아이디문제언어결과실행 시간메모리
1023809vjudge1Knapsack (NOI18_knapsack)C++17
0 / 100
1 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]; } const int maxN = 1e5+5; const int maxV = 2e3+5; int cnt = 0; pair<int, int> item[maxN*30]; //.fi = value; .se = weight; int f[maxV]; signed main(){ int S,N; cin >> S >> N; for(int i = 1; i <= N; ++i){ int v,w,k; cin >> v >> w >> k; for(int j = 1; j <= k; j <<= 1){ item[cnt++] = make_pair(v*j,w*j); k -= j; } if(k > 0){ item[cnt++] = make_pair(v*k,w*k); } } for(int i = 1; i <= cnt; ++i){ for(int j = S; j >= item[i].ss; --j){ f[j] = max(f[j], f[j-item[i].ss] + item[i].ff); } } cout << f[S] << '\n'; } // NEED TO FAST CIN && COUT // const int fastIO = [](){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }();

컴파일 시 표준 에러 (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...