제출 #1293320

#제출 시각아이디문제언어결과실행 시간메모리
1293320HoriaHaivasCloud Computing (CEOI18_clo)C++20
100 / 100
637 ms2248 KiB
#include<bits/stdc++.h> #define debug(x) cerr << #x << " " << x << "\n" #define debugs(x) cerr << #x << " " << x << " " #pragma GCC optimize("Ofast") #define int long long using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int range_rng(int l, int r) { return uniform_int_distribution<int>(l,r)(rng); } struct event { bool type; int c; int f; int v; }; bool cmp(event a, event b) { if (a.f!=b.f) return a.f<b.f; if (a.type!=b.type) return a.type>b.type; } const int inf=1e18; event buy[2005]; event sell[2005]; event all[4005]; int dp[2][100005]; signed main() { /* ifstream fin("arbore.in"); ofstream fout("arbore.out"); */ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,i,j,cnt,ans; cin >> n; cnt=0; for (i=1;i<=n;i++) { buy[i].type=0; cin >> buy[i].c >> buy[i].f >> buy[i].v; cnt++; all[cnt]=buy[i]; } cin >> m; for (i=1;i<=m;i++) { sell[i].type=1; cin >> sell[i].c >> sell[i].f >> sell[i].v; cnt++; all[cnt]=sell[i]; } sort(all+1,all+1+cnt,cmp); for (i=0;i<=1;i++) { for (j=1;j<=100000;j++) { dp[i][j]=-inf; } } ans=0; for (i=cnt;i>=1;i--) { for (j=0;j<=100000;j++) dp[i%2][j]=dp[(i+1)%2][j]; if (all[i].type==1) { for (j=all[i].c;j<=100000;j++) { if (dp[(i+1)%2][j]!=-inf) dp[i%2][j-all[i].c]=max(dp[i%2][j-all[i].c],dp[(i+1)%2][j]+all[i].v); } } else { for (j=0;j<=100000-all[i].c;j++) { if (dp[(i+1)%2][j]!=-inf) dp[i%2][j+all[i].c]=max(dp[i%2][j+all[i].c],dp[(i+1)%2][j]-all[i].v); } } for (j=0;j<=100000;j++) ans=max(ans,dp[i%2][j]); } cout << ans; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

clo.cpp: In function 'bool cmp(event, event)':
clo.cpp:30:1: warning: control reaches end of non-void function [-Wreturn-type]
   30 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...