| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 710803 | vjudge1 | Knapsack (NOI18_knapsack) | C++17 | 200 ms | 35436 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
بسم الله الرحمن الرحيم
وَاتَّقُوا يَوْمًا تُرْجَعُونَ فِيهِ إِلَى اللَّهِ ۖ ثُمَّ تُوَفَّىٰ كُلُّ نَفْسٍ مَّا كَسَبَتْ وَهُمْ لَا يُظْلَمُونَ
In The name if allah
And fear a Day when you will be returned to Allah
Then every soul will be compensated for what it earned
and they will not be treated unjustly.
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
void init() {
cin.tie(nullptr);
std::istream::sync_with_stdio(false);
cout.tie(nullptr);
std::ostream::sync_with_stdio(false);
}
const long long mod = 1e9 + 7;
vector<pair<int, int>> vec[2001];
long long dp[2001][2001];
long long n, s;
long long solve(int i, int w) {
if (w == 0)
return w;
if (i > w)
return 0;
long long &ret = dp[i][w];
if (~ret)
return ret;
ret = solve(i + 1, w);
bool is = true;
long long ans = 0, tot = 0;
for (int j = 0; j < vec[i].size(); ++j) {
for (int k = 1; k <= vec[i][j].second; ++k) {
ans += vec[i][j].first;
tot += i;
if (w >= tot)
ret = max(ret, solve(i + 1, w - tot) + ans);
else {
is = false;
break;
}
}
if (!is)
break;
}
return ret;
}
int main() {
init();
cin >> s >> n;
memset(dp, -1, sizeof dp);
int w, v, k;
for (int i = 0; i < n; ++i) {
cin >> v >> w >> k;
vec[w].emplace_back(v, k);
}
for (int i = 1; i <= s; ++i)
sort(vec[i].begin(), vec[i].end(), greater<pair<int, int >>());
cout << solve(1, s);
}
컴파일 시 표준 에러 (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... | ||||
