이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "CEOI18_clo"
void Fi(){
if(fopen(PROB".inp", "r")){
freopen(PROB".inp", "r", stdin);
freopen(PROB".out", "w", stdout);
}
}
const int N = 2000 + 1;
const int C = 50 + 1;
int n, m;
int c1[N], f1[N], v1[N], a[N];
int c2[N], f2[N], v2[N], b[N];
ll dp[N * C];
void enter(){
cin >> n;
FORU(i, 1, n){
cin >> c1[i] >> f1[i] >> v1[i];
a[i] = i;
}
sort(a + 1, a + n + 1, [&](const int &i, const int &j){
return f1[i] < f1[j];
}
);
cin >> m;
FORU(i, 1, m){
cin >> c2[i] >> f2[i] >> v2[i];
b[i] = i;
}
sort(b + 1, b + m + 1, [&](const int &i, const int &j){
return f2[i] < f2[j];
}
);
}
void buy(int x){
FORD(i, 50 * n, 0) if(c1[a[x]] <= i){
dp[i] = min(dp[i], dp[i - c1[a[x]]] + v1[a[x]]);
} else break;
}
void use(int x){
FORU(i, 0, 50 * n) if(i + c2[b[x]] <= 50 * n){
dp[i] = min(dp[i], dp[i + c2[b[x]]] - v2[b[x]]);
} else break;
}
void solve(){
FORU(i, 1, 50 * n) dp[i] = 1e9;
int i = n, j = m;
for(; i >= 1 && j >= 1; ){
if(f1[a[i]] >= f2[b[j]]){
int ii = i;
while(ii >= 1 && f1[a[ii]] == f1[a[i]]){
// cout << a[ii] << " ";
buy(ii--);
}
// cout << "| a\n";
i = ii;
} else{
int jj = j;
while(jj >= 1 && f2[b[jj]] == f2[b[j]]){
// cout << b[jj] << " ";
use(jj--);
}
// cout << "| b\n";
j = jj;
}
// FORU(k, 0, 20) cout << dp[k] << " ";
// cout << '\n';
}
while(j >= 1) use(j--);
ll ans = 0;
FORU(i, 0, 50 * n) ans = min(ans, dp[i]);
cout << -ans;
}
int main(){
IOS;
Fi();
enter();
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'void Fi()':
clo.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | freopen(PROB".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen(PROB".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |