제출 #1088609

#제출 시각아이디문제언어결과실행 시간메모리
1088609shidou26Knapsack (NOI18_knapsack)C++14
73 / 100
1091 ms17300 KiB
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define all(v) v.begin(), v.end()
#define int long long

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;

const int N = 1e6 + 3;

int n, m;

int num = 0;
int dp[N], wes[N], ves[N];

void prepare() {

}

void input() {
    cin >> m >> n;

    for(int i = 1; i <= n; i++) {
        int w, v, a; cin >> v >> w >> a;
        int two = 1;
        while(two <= a) {
            wes[++num] = w * two;
            ves[num] = v * two;
            a -= two;
            two *= 2;
        }
        if(a > 0) {
            wes[++num] = w * a;
            ves[num] = v * a;
        }
    }
}

void process() {
    for(int i = 1; i <= num; i++) {
        for(int j = m; j >= wes[i]; j--) {
            dp[j] = max(dp[j], dp[j - wes[i]] + ves[i]);
        }
    }
    cout << dp[m] << endl;
}

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

    #define task "quantity"
    if(fopen(task".INP", "r")) {
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }

    prepare();

    int testcase = 1; // cin >> testcase;
    for(int i = 1; i <= testcase; i++) {
        input();
        process();
    }

    return 0;
}

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

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