이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1e9 + 7;
ll binpow(ll a, ll p, int mod = MOD) {
ll res = 1;
while (p) {
if (p & 1) {
(res *= a) %= mod;
}
p >>= 1;
(a *= a) %= mod;
}
return res;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
struct Comp {
int cores;
ll rate, price;
};
bool operator <(const Comp& a, const Comp& b) {
return a.rate < b.rate;
}
void solve() {
int n;
cin >> n;
vector<Comp> computers(n);
for (int i = 0; i < n; i++) {
cin >> computers[i].cores >> computers[i].rate >> computers[i].price;
}
sort(computers.begin(), computers.end());
int m;
cin >> m;
vector<Comp> orders(m);
for (int i = 0; i < m; i++) {
cin >> orders[i].cores >> orders[i].rate >> orders[i].price;
}
sort(orders.rbegin(), orders.rend());
int top = n * 50 + 1;
vector<ll> dp(top, LLONG_MIN);
dp[0] = 0;
for (auto& [cores, rate, price] : orders) {
while (!computers.empty() && computers.back().rate >= rate) {
for (int i = top - 1; i >= computers.back().cores; i--) {
if (dp[i - computers.back().cores] == LLONG_MIN) continue;
dp[i] = max(dp[i], dp[i - computers.back().cores] - computers.back().price);
}
computers.pop_back();
}
for (int i = 0; i < top - cores; i++) {
if (dp[i + cores] == LLONG_MIN) continue;
dp[i] = max(dp[i], dp[i + cores] + price);
}
}
cout << *max_element(dp.begin(), dp.end()) << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
for (int tc = 1; tc <= T; tc++) {
// cout << "Case #" << tc << ": ";
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization ("O3")
|
# | 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... |