제출 #1093677

#제출 시각아이디문제언어결과실행 시간메모리
1093677luvnaCloud Computing (CEOI18_clo)C++14
100 / 100
380 ms2140 KiB
#include<bits/stdc++.h> #define endl "\n" #define int long long using namespace std; typedef long long ll; template<class T> bool maximize(T& a, T b) {if(a < b) return a = b, true; return false;} const int N = 2005; const ll INF = 1e18; struct computer{ int cores, rate, price; bool operator < (const computer& a) const{ return (rate != a.rate) ? (rate > a.rate) : (cores > a.cores); } }; int n, m; computer a[N<<1]; vector<ll> dp; void solve(){ cin >> n; int max_cores = 0; for(int i = 1; i <= n; i++){ int cores, rate, price; cin >> cores >> rate >> price; a[i] = {cores, rate, -price}; max_cores += cores; } cin >> m; for(int i = 1; i <= m; i++){ int cores, rate, price; cin >> cores >> rate >> price; a[i+n] = {-cores, rate, price}; } n += m; sort(a + 1, a + 1 + n); dp.resize(max_cores + 5, -INF); dp[0] = 0; for(int i = 1; i <= n; i++){ int cores = a[i].cores, p = a[i].price; vector<ll> f = dp; if(cores > 0){ //computer //knapsack : f[i] = dp[i-cores] + p for(int j = cores; j <= max_cores; j++){ f[j] = max(f[j], dp[j-cores] + 1LL*p); } } else{ //task //knapsack : f[i] = dp[i + cores] + p cores = -cores; for(int j = max_cores - cores; j >= 0; j--){ f[j] = max(f[j], dp[j + cores] + 1LL*p); } } swap(dp, f); } ll ans = 0; for(int i = 0; i <= max_cores; i++) maximize(ans, dp[i]); cout << ans; } signed main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "task" if(fopen(task".INP", "r")){ freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } int t; t = 1; //cin >> t; while(t--) solve(); }

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

clo.cpp: In function 'int main()':
clo.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...