이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define X first
#define Y second
#define all(x) begin(x), end(x)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, b, a) for(int i = (b); i >= (a); i--)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define mxx max_element
#define mnn min_element
#define SQR(x) (1LL * (x) * (x))
#define MASK(i) (1LL << (i))
#define Point Vector
#define left Left
#define right Right
#define div Div
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<db, db> pdb;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef pair<ll, int> pli;
typedef pair<ll, pii> plii;
template<class A, class B>
bool maximize(A& x, B y) {
if (x < y) return x = y, true; else return false;
}
template<class A, class B>
bool minimize(A& x, B y) {
if (x > y) return x = y, true; else return false;
}
/* END OF TEMPLATE */
const int N = 40007;
struct cloud {
int c, f, v;
bool isMc;
cloud() {
c = f = v = 0;
isMc = false;
}
} a[N], b[N];
int n, m;
ll dp[2][100007];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
FOR(i, 1, n) {
cin>>a[i].c>>a[i].f>>a[i].v;
a[i].isMc = true;
}
cin>>m;
FOR(i, 1, m) cin>>a[i + n].c>>a[i + n].f>>a[i + n].v;
n+=m;
sort(a + 1, a + 1 + n, [](cloud& a, cloud& b) {
return (a.f != b.f ? a.f > b.f : a.isMc > b.isMc);
});
FOR(i, 0, 1)
FOR(j, 0, 100000) dp[i][j] = -1e18;
dp[0][0] = 0;
// FOR(i, 1, n) cout<<a[i].c<<" "<<a[i].f<<" "<<a[i].v<<"\n";
REP(i, 0, n) {
FOR(j, 0, 100000) dp[i & 1 ^ 1][j] = -1e18;
FOR(j, 0, 100000)
if (dp[i & 1][j] != -1e18) {
maximize(dp[i & 1 ^ 1][j], dp[i & 1][j]);
if (a[i + 1].isMc) {
maximize(dp[i & 1 ^ 1][min(j + a[i + 1].c, 100000)], dp[i & 1][j] - a[i + 1].v);
}
else {
if (j >= a[i + 1].c)
maximize(dp[i & 1 ^ 1][j - a[i + 1].c], dp[i & 1][j] + a[i + 1].v);
}
}
}
ll res = 0;
FOR(j, 0, 100000) maximize(res, dp[n & 1][j]);
cout<<res;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int main()':
clo.cpp:77:32: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
77 | FOR(j, 0, 100000) dp[i & 1 ^ 1][j] = -1e18;
| ~~^~~
clo.cpp:80:31: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
80 | maximize(dp[i & 1 ^ 1][j], dp[i & 1][j]);
| ~~^~~
clo.cpp:82:35: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
82 | maximize(dp[i & 1 ^ 1][min(j + a[i + 1].c, 100000)], dp[i & 1][j] - a[i + 1].v);
| ~~^~~
clo.cpp:86:39: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
86 | maximize(dp[i & 1 ^ 1][j - a[i + 1].c], dp[i & 1][j] + a[i + 1].v);
| ~~^~~
# | 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... |