| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1180638 | souvenir_vayne | Knapsack (NOI18_knapsack) | C++20 | 466 ms | 327680 KiB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <chrono>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define fin cin
#define fout cout
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cerr << "DEBUG " << x << endl
#define debug2(x, y) cerr << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cerr << "DEBUG " << x << " " << y << " " << z << endl
#define debug4(x, y, z, o) cerr << "DEBUG " << x << " " << y << " " << z << " " << o << endl
#define all(x) x.begin(), x.end()
#define left esquerda
#define lb lower_bound
#define right direita
using namespace std;
void setIO(string s) {
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
typedef pair<int, int> pii;
typedef vector<vector<char>> mat;
typedef pair<int, string> pis;
const ll mod = 1e9 + 7, MAXN = 2e5 + 5;
typedef vector<int> vi;
typedef pair<int, pair<int, int>> piii;
int dp[2][2001], ans = 0;
vector<int> items[2001];
void solve() {
int n, s;
int v, w, k;
cin >> s >> n;
for(int i = 0; i < n; i++) {
cin >> v >> w >> k;
k = min(k, s/w);
for(int j = 0; j < k; j++)
items[w].push_back(v);
}
int i = 0;
for(int jooj = 1; jooj < 2001; jooj++) {
sort(all(items[jooj]), greater<int>());
for(int verv = 0; verv < min((int)items[jooj].size(), s/jooj); verv++) {
for(int j = s; j >= 0; j--) {
if(!i && j >= jooj)
dp[i][j] = items[jooj][verv];
else if(i) {
dp[i & 1][j] = dp[!(i & 1)][j];
if(j >= jooj)
dp[i & 1][j] = max(dp[i & 1][j], dp[!(i & 1)][j - jooj] + items[jooj][verv]);
}
ans = max(ans, dp[i & 1][j]);
}
i++;
}
}
cout << ans << endl;
}
int32_t main() {
solve();
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... | ||||
