제출 #1167209

#제출 시각아이디문제언어결과실행 시간메모리
1167209SmuggingSpunCloud Computing (CEOI18_clo)C++20
100 / 100
1158 ms3788 KiB
#include<bits/stdc++.h> #define taskname "A" using namespace std; typedef long long ll; template<class T>void minimize(T& a, T b){ if(a > b){ a = b; } } template<class T>void maximize(T& a, T b){ if(a < b){ a = b; } } const int lim = 2e3 + 5; const int INF = 2e9; struct Data{ int c, f, v; bool operator <(const Data& other){ return this->f < other.f; } }; int n, m; Data a[lim], b[lim]; namespace sub4{ const int LIM = 1e5 + 5; ll dp_a[LIM], dp_b[LIM]; void solve(){ memset(dp_a, 0x0f, sizeof(dp_a)); memset(dp_b, -0x0f, sizeof(dp_b)); ll ans = dp_a[0] = dp_b[0] = 0; for(int i = 1; i <= n; i++){ for(int j = LIM - 1; j >= a[i].c; j--){ minimize(dp_a[j], dp_a[j - a[i].c] + a[i].v); } } for(int i = LIM - 2; i > -1; i--){ minimize(dp_a[i], dp_a[i + 1]); } for(int i = 1; i <= m; i++){ for(int j = LIM - 1; j >= b[i].c; j--){ maximize(dp_b[j], dp_b[j - b[i].c] + b[i].v); } } for(int i = 0; i < LIM; i++){ maximize(ans, dp_b[i] - dp_a[i]); } cout << ans; } } namespace sub1235{ const int LIM_R = 105; ll dp[2][lim][LIM_R]; void solve(){ a[n + 1].f = INF; bool cur = true, pre = false; memset(dp, -0x0f, sizeof(dp)); dp[cur][m][0] = 0; for(int i = n; i > -1; i--, swap(cur, pre)){ for(int j = 0; j <= m; j++){ memset(dp[pre][j], -0x0f, sizeof(dp[pre][j])); } for(int j = m; j > -1; j--){ for(int r = 0; r < LIM_R; r++){ maximize(dp[pre][j][r], dp[cur][j][r]); if(j > 0){ maximize(dp[cur][j - 1][r], dp[cur][j][r]); } if(j > 0 && a[i + 1].f >= b[j].f && r >= b[j].c){ maximize(dp[cur][j - 1][r - b[j].c], dp[cur][j][r] + b[j].v); } if(r + a[i].c < LIM_R){ maximize(dp[pre][j][r + a[i].c], dp[cur][j][r] - a[i].v); } } } } cout << *max_element(dp[cur][0], dp[cur][0] + LIM_R); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); } cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i].c >> a[i].f >> a[i].v; } cin >> m; for(int i = 1; i <= m; i++){ cin >> b[i].c >> b[i].f >> b[i].v; } sort(a + 1, a + n + 1); sort(b + 1, b + m + 1); if(a[n].f == 1 && b[m].f == 1){ sub4::solve(); } else{ sub1235::solve(); } }

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

clo.cpp: In function 'int main()':
clo.cpp:84:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...