이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#include "functions.h"
#define FOR(x,y) for(int x = 0; x < y; x++)
#define ALLR(x) x.begin(),x.end()
#define con continue
#define ll long long
#define LINF LLONG_MAX
#define INF INT_MAX
#define pii pair<int,int>
#define vi vector <int>
#define pb push_back
#define F first
#define S second
#define len(x) x.length()
#define sz(x) x.size()
#define SEE(v) for(auto x : v) cout << x << " "; cout << endl;
#define buy 1
#define sell 0
#define yes 1
#define no 0
using namespace std;
int main(){
//freopen("test.txt","r",stdin);
//vector pair<pii, pii> com;
vector <pair<pair<int,int>, pair<int, int> > > com;
int n;
cin >> n;
FOR(j, n)
{
int x,y,z;
cin >> x >> y >> z;
com.pb(make_pair(make_pair(y, 1), make_pair(x, z)));
}
int m;
cin >> m;
FOR(j, m)
{
int x,y,z;
cin >> x >> y >> z;
com.pb(make_pair(make_pair(y, 0), make_pair(x, z)));
}
sort(ALLR(com));
reverse(ALLR(com));
int dp[2][111115]; //dp[i][j], 0 is previous situation, j is cores lefted
FOR(j, 111115) dp[0][j] = dp[1][j] = -INF;
dp[1][0] = 0; //1 is "previous" && we start with 0 core
FOR(j, n + m)
{
int cur = j % 2, prev = ((cur == 0) ? 1 : 0); //prev points to previous situation
//cout << cur << " " << prev << endl;
int f = com[j].F.F, type = com[j].F.S, core = com[j].S.F, cost = com[j].S.S;
//cout << f << " " << type << " " << core << " " << cost << endl;
//set current situation to -INF
//check all posibble # of cores
//if have cores, then process buy || sell
FOR(k, 111111) dp[cur][k] = -INF;
FOR(k, 111111)
{
if(dp[prev][k] > -INF)
{
int p = dp[prev][k];
if(dp[cur][k] < p) dp[cur][k] = p;
if(type == buy)
{
if(dp[cur][k + core] < p - cost) dp[cur][k + core] = p - cost;
}
else// if(type == sell)
{
if(k >= core) if(dp[cur][k - core] < p + cost) dp[cur][k - core] = p + cost;
}
}
}
}
int ans = 0;
FOR(j, 111111)
{
ans = max(ans, dp[(n + m - 1) % 2][j]);
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int main()':
clo.cpp:57:7: warning: unused variable 'f' [-Wunused-variable]
int f = com[j].F.F, type = com[j].F.S, core = com[j].S.F, cost = com[j].S.S;
^
# | 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... |