| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 380674 | saarang123 | Knapsack (NOI18_knapsack) | C++17 | 3 ms | 748 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 1e15, N = 2002;
vector<array<int, 2>> a[N];
int ans = 0;
signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("C:/Users/shriya-student/Documents/competitive programming/newproj/input.txt", "r", stdin);
    freopen("C:/Users/shriya-student/Documents/competitive programming/newproj/output.txt", "w", stdout);
    #endif
    int n, s;
    cin >> s >> n;
    for(int w, c, k, i = 0; i < n; i++) {
    	cin >> c >> w >> k;
    	k = min(k, s / w);
    	a[w].push_back({c, k});
    }
    vector<array<int, 2>> costs;
    for(int i = 1; i <= s; i++) sort(a[i].begin(), a[i].end(), greater<>());
    for(int i = 1; i <= s; i++) {
    	int left = s / i;
    	for(auto x : a[i]) {
    		int c = x[0], k = x[1];
    		for(int j = 0; j < k && left > 0; j++, left--) {
    			costs.push_back({i, c});
    		}
    	}
    }
    n = costs.size();
    vector<vector<int>> dp(n + 2, vector<int>(s + 2, -inf));
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++) {
    	for(int j = 0; j <= s; j++) {
    		dp[i][j] = dp[i - 1][j];
    		if(j - costs[i - 1][0] >= 0)
    			dp[i][j] = max(dp[i][j], dp[i - 1][j - costs[i - 1][0]] + costs[i - 1][1]);
    		ans = max(ans, dp[i][j]);
    	}
    }
    cout << ans << '\n';
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
