| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 572945 | BenyKarimi | Knapsack (NOI18_knapsack) | C++17 | 26 ms | 33236 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define For(i, x, n) for(int i = x; i < n; i++)
#define Rof(i, x, n) for(int i = n - 1; i >= x; i--)
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define F first
#define S second
#define pb push_back
#define po pop_back
#define En endl
#define endl "\n"
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend();
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PLL> VPLL;
const int MN = 2e3 + 5;
const int MOD = 1e9 + 7;
const int LOG = 20;
const LL INF = 1e18 + 7;
LL s, n, v, maxw;
LL dp[MN][MN], k[MN], w[MN];
VLL keep[MN];
int main () {
IOS;
cin >> s >> n;
VPLL forsort;
For (i, 0, n) {
cin >> v >> w[i] >> k[i];
maxw = max(maxw, w[i]);
forsort.pb({v, i});
}
sort(ALL(forsort));
reverse(ALL(forsort));
for (PII it : forsort) {
For (i, 0, k[it.S]) {
if (keep[w[it.S]].size() == MN - 5) break;
keep[w[it.S]].pb(it.F);
}
}
For (i, 1, maxw + 1) {
For (j, 1, s + 1) {
dp[i][j] = dp[i - 1][j];
LL sum = 0;
For (k, 0, keep[i].size()) {
sum = sum + keep[i][k];
LL jon = 1ll * (k + 1) * i;
if (jon > j) break;
dp[i][j] = max(dp[i][j], dp[i - 1][j - jon] + sum);
}
}
}
cout << dp[maxw][s] << En;
}컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
