이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
struct Object {
int c;
ll f, v;
bool operator<(Object B) { return f > B.f; }
} objects[4001];
ostream& operator<<(ostream& cout, Object X) { return cout << X.c << ' ' << X.f << ' ' << X.v; }
ll dp[2][100001];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n;
FOR(i, 0, n) {
cin >> objects[i].c >> objects[i].f >> objects[i].v;
objects[i].v *= -1;
}
cin >> m;
FOR(i, n, n + m) {
cin >> objects[i].c >> objects[i].f >> objects[i].v;
objects[i].c *= -1;
}
sort(objects, objects + n + m);
FOR(i, 0, 2) FOR(j, 0, 100001) dp[i][j] = INT_MIN;
dp[1][0] = 0;
int mx = 0;
FOR(i, 0, n + m) {
FOR(j, 0, mx + 1 + objects[i].c) {
if (j >= objects[i].c)
dp[i & 1][j] = max(dp[1 - i & 1][j], dp[1 - i & 1][j - objects[i].c] + objects[i].v);
else dp[i & 1][j] = dp[1 - i & 1][j];
}
mx += max(0, objects[i].c);
FOR(j, 0, mx + 1) dp[1 - i & 1][j] = INT_MIN;
}
cout << *max_element(dp[1 - (n + m) & 1], dp[1 - (n + m) & 1] + mx + 1);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int main()':
clo.cpp:38:41: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
dp[i & 1][j] = max(dp[1 - i & 1][j], dp[1 - i & 1][j - objects[i].c] + objects[i].v);
~~^~~
clo.cpp:38:59: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
dp[i & 1][j] = max(dp[1 - i & 1][j], dp[1 - i & 1][j - objects[i].c] + objects[i].v);
~~^~~
clo.cpp:39:38: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
else dp[i & 1][j] = dp[1 - i & 1][j];
~~^~~
clo.cpp:42:32: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
FOR(j, 0, mx + 1) dp[1 - i & 1][j] = INT_MIN;
~~^~~
clo.cpp:45:31: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
cout << *max_element(dp[1 - (n + m) & 1], dp[1 - (n + m) & 1] + mx + 1);
~~^~~~~~~~~
clo.cpp:45:52: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
cout << *max_element(dp[1 - (n + m) & 1], dp[1 - (n + m) & 1] + mx + 1);
~~^~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |