제출 #892805

#제출 시각아이디문제언어결과실행 시간메모리
892805vjudge1Knapsack (NOI18_knapsack)C++17
0 / 100
2 ms344 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> p32; typedef pair<ll,ll> p64; typedef pair<double,double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int> > vv32; typedef vector<vector<ll> > vv64; typedef vector<vector<p64> > vvp64; typedef vector<p64> vp64; typedef vector<p32> vp32; #define mp make_pair #define pb push_back #define fi first #define se second #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) const int N = 2e5 + 5; const int mod = 1e9 + 7; int n, W; vector<p64> b; ll dp[N]; void readata(){ cin >> W >> n; for (int i = 1; i <= n; ++i){ int w, v, a; cin >> v >> w >> a; for (int i = 1; i <= a; i *= 2){ if (a >= i){ b.push_back({w * i, v * i}); a -= i; } } if (a > 0){ b.push_back({w * a, v * a}); } } } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt","r", stdin); freopen("output.txt","w", stdout); #endif fast_cin(); readata(); ll ans = 0; for (int i = 0; i < b.size(); ++i){ for (int j = W; j >= b[i].fi; --j){ dp[j] = max(dp[j], dp[j - b[i].fi] + b[i].se); ans = max(ans, dp[j]); } } cout << ans; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'int main()':
knapsack.cpp:49:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for (int i = 0; i < b.size(); ++i){
      |                     ~~^~~~~~~~~~
knapsack.cpp:43:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     freopen("input.txt","r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:44:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     freopen("output.txt","w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...