이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cassert>
#include <math.h>
using namespace std;
#define endl "\n"
#define int int64_t
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FOR0(i,a) FOR(i,0,a)
#define FOR1(i,a) for (int i = (1); i <= (a); ++i)
#define TRAV(a,x) for (auto& a: x)
using pii = pair<int,int>;
using vi = vector<int>;
struct transaction{
int cores;
int frames;
int profit;
};
bool cmp(transaction a, transaction b){
if(a.frames!=b.frames){
return a.frames>b.frames;
}else{
return a.profit<b.profit;
}
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin>>N;
int cores=0;
vector<transaction> transactions;
FOR0(i,N){
int a,b,c;
cin>>a>>b>>c;
cores+=a;
transactions.pb({a,b,-c});
}
int M;
cin>>M;
FOR0(i,M){
int a,b,c;
cin>>a>>b>>c;
transactions.pb({-a,b,c});
}
sort(transactions.begin(),transactions.end(),cmp);
// TRAV(i,transactions){
// cout<<i.cores<<" "<<i.frames<<" "<<i.profit<<endl;
// }
int dp[transactions.size()+1][cores+1];
FOR0(i,transactions.size()+1){
FOR0(j,cores+1){
dp[i][j]=-10100000000000000;
}
}
dp[0][0]=0;
int num=1;
TRAV(i,transactions){
for(int c=0;c<=cores;c++){
dp[num][c]=dp[num-1][c];
}
int curCores=i.cores;
for(int c=0;c<=cores;c++){
int left=c-i.cores;
if(left>=0 && left<=cores && dp[num-1][left]!=(-10100000000000000)){
dp[num][c]=max(dp[num][c],dp[num-1][left]+i.profit);
// if(dp[num][c]==4550){
// cout<<"DJIOEWJODE "<<c<<" "<<dp[num-1][left]<<" "<<left<<endl;
// }
}
}
num++;
}
// FOR0(i,transactions.size()+1){
// FOR0(j,cores+1){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl<<endl<<endl;
// }
int ans=-1;
FOR0(i,cores+1){
ans=max(ans,dp[N+M][i]);
}
cout<<ans<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int32_t main()':
clo.cpp:19:40: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<transaction>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
| ^
clo.cpp:20:19: note: in expansion of macro 'FOR'
20 | #define FOR0(i,a) FOR(i,0,a)
| ^~~
clo.cpp:65:2: note: in expansion of macro 'FOR0'
65 | FOR0(i,transactions.size()+1){
| ^~~~
clo.cpp:76:7: warning: unused variable 'curCores' [-Wunused-variable]
76 | int curCores=i.cores;
| ^~~~~~~~
# | 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... |