제출 #1137145

#제출 시각아이디문제언어결과실행 시간메모리
1137145hoa208Knapsack (NOI18_knapsack)C++20
17 / 100
1 ms2376 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
#define t_test int t;cin >> t;while(t--)
const ll mod = 1e9 + 7;
const ll INF = 1e17;
const ll N = 1e2 + 10;
const ll W = 2e3 + 10;
ll S, n, m;
vector<pa> a;
namespace subX {
    void slove() {
        
    }
}
ll dp[N][W];
void hbmt() {
    // inp
    cin >> S >> n;
    a.push_back({0, 0});
    FOR(i, 1, n) {
        ll v, w, k;
        cin >> v >> w >> k;
        ll heso = 1, sum = 1;
        a.push_back({v, w});
        while(1) {
            heso *= 2;
            sum += heso;
            if(sum > k) break;
            a.push_back({heso * v, heso * w});
        }        
    }
    FOR(i, 1, a.size() - 1) {
        ll v = a[i].fi, w = a[i].se;
        FOR(j, 0, S) {
            dp[i][j] = dp[i - 1][j];
            if(j >= w) {
                dp[i][j] = max(dp[i][j] , dp[i - 1][j - w] + v);
            }
        }
    }
    cout << dp[a.size() - 1][S];
    // slove
   // return subX::slove();
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    if(fopen("hbmt.inp", "r")) {
        freopen("hbmt.inp", "r", stdin);
        freopen("hbmt.out", "w", stdout);
    }
    
    // t_test 
    hbmt();
    return 0;
}

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

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