제출 #1102281

#제출 시각아이디문제언어결과실행 시간메모리
1102281tuannmKnapsack (NOI18_knapsack)C++17
73 / 100
1090 ms2900 KiB
#include<bits/stdc++.h> #define ii pair<int, int> #define ll pair<long long, long long> #define fi first #define se second #define pb push_back using namespace std; const int mod[2] = {1000000007, 998244353}; const int N = 1e5 + 1; const string NAME = ""; int n, s; array<int, 3> a[N]; long long dp[N]; template<class X, class Y> bool maximize(X &x, const Y &y) { if (x < y) { x = y; return true; } else return false; } void inp(){ cin >> s >> n; for(int i = 1; i <= n; ++i) cin >> a[i][0] >> a[i][1] >> a[i][2]; } void solve(){ for(int i = 1; i <= s; ++i) dp[i] = -1e16; for(int i = 1; i <= n; ++i){ for(int w = s; w > 0; --w){ for(int j = 1; j <= min(a[i][2], w / a[i][1]); ++j) maximize(dp[w], dp[w - j * a[i][1]] + 1LL * a[i][0] * j); } } long long ans = 0; for(int i = 0; i <= s; ++i) maximize(ans, dp[i]); cout << ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen((NAME + ".inp").c_str(), "r")){ freopen((NAME + ".inp").c_str(), "r", stdin); freopen((NAME + ".out").c_str(), "w", stdout); } inp(); solve(); }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen((NAME + ".out").c_str(), "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...