제출 #676071

#제출 시각아이디문제언어결과실행 시간메모리
676071madtuberKnapsack (NOI18_knapsack)C++14
29 / 100
3 ms1876 KiB
#include <bits/stdc++.h> #define all(x) begin(x),end(x) #define fir first #define sec second #define sz(x) x.size() #define pb push_back using namespace std; using ll = long long; using vi = vector<int>; using pi = pair<int,int>; using pdb = pair<double,double>; using pll = pair<ll,ll>; using vll = vector<ll>; const double EPS = (1e-6); void setio(string s){ freopen((s + ".in").c_str(),"r",stdin); freopen((s + ".out").c_str(),"w",stdout); } struct Item{ ll v, w, k; }; const int MXN = 1e5+1; const int MXS = 2001; ll dp[MXN][MXS]; void solve(){ ll s, n; cin >> s >> n; vector<Item> a(n); for(auto& i :a){ cin >> i.v >> i.w >> i.k; } for(int i{1}; i <= n; i++){ for(int j{}; j <= s; j++){ dp[i][j] = max(dp[i][j], dp[i-1][j]); ll mx = min((s-j)/a[i-1].w, a[i-1].k); dp[i][j+mx*a[i-1].w] = max(dp[i][j+mx*a[i-1].w], dp[i-1][j] + mx*a[i-1].v); } } cout << dp[n][s]; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; while(t--){ solve(); } return 0; }

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

knapsack.cpp: In function 'void setio(std::string)':
knapsack.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen((s + ".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen((s + ".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...