제출 #1344807

#제출 시각아이디문제언어결과실행 시간메모리
1344807hojiakbar2011Knapsack (NOI18_knapsack)C++20
73 / 100
1094 ms448 KiB
#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define ll long long
#define int long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define mp make_pair

void setIO(string s = "") {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    if (!s.empty()) {
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
}

void solve() {
    
}

signed main() {
    setIO(); // or setIO("file")
    ll s, n;
    cin>>s>>n;
    vector<ll> dp(s+1, 0);
    while(n--){
        ll v, w, k;
        cin>>v>>w>>k;
        k=min(k, s/w);
        while(k--){
            for(int i=s;i>=w;i--){
                dp[i]=max(dp[i], dp[i-w]+v);
            }
        }
    }
    cout<<dp[s];

}

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

knapsack.cpp: In function 'void setIO(std::string)':
knapsack.cpp:18:16: 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:16: 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...