제출 #1091627

#제출 시각아이디문제언어결과실행 시간메모리
1091627Zero_OPCloud Computing (CEOI18_clo)C++14
72 / 100
280 ms1372 KiB
#include<bits/stdc++.h> using namespace std; #define sz(v) (int)v.size() #define all(v) begin(v), end(v) #define compact(v) v.erase(unique(all(v)), end(v)) #define dbg(v) "[" #v " = " << (v) << "]" #define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define rep(i, l, r) for(int i = (l); i < (r); ++i) using ll = long long; using vi = vector<int>; using vl = vector<long long>; using ld = long double; template<typename T> bool minimize(T& a, const T& b){ if(a > b){ return a = b, true; } return false; } template<typename T> bool maximize(T& a, const T& b){ if(a < b){ return a = b, true; } return false; } template<int dimension, typename T> struct tensor : public vector<tensor<dimension - 1, T>> { static_assert(dimension > 0, "Dimension must be positive !\n"); template<typename... Args> tensor(int n = 0, Args... args) : vector<tensor<dimension - 1, T>> (n, tensor<dimension - 1, T>(args...)) {} }; template<typename T> struct tensor<1, T> : public vector<T> { tensor(int n = 0, T val = T()) : vector<T>(n, val) {} }; const int MAX = 2e3 * 50 + 1; const ll inf = 1e18; struct item{ int need, value, earn; item(int need, int value, int earn) : need(need), value(value), earn(earn) {} bool operator < (const item& o){ return value > o.value; } }; void testcase(){ int n; cin >> n; vector<item> items; while(n--){ int c, f, p; cin >> c >> f >> p; items.push_back(item(c, f, -p)); } int m; cin >> m; while(m--){ int c, f, p; cin >> c >> f >> p; items.push_back(item(-c, f, p)); } sort(all(items)); vector<ll> dp(MAX, -inf); dp[0] = 0; for(int i = 0; i < sz(items); ++i){ if(items[i].need < 0){ for(int j = 0; j < MAX + items[i].need; ++j){ maximize(dp[j], dp[j - items[i].need] + items[i].earn); } } else{ for(int j = MAX - 1; j >= items[i].need; --j){ maximize(dp[j], dp[j - items[i].need] + items[i].earn); } } } cout << *max_element(all(dp)); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); file("task"); int T = 1; // cin >> T; while(T--){ testcase(); } return 0; }

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

clo.cpp: In function 'int main()':
clo.cpp:9:55: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:98:5: note: in expansion of macro 'file'
   98 |     file("task");
      |     ^~~~
clo.cpp:9:88: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:98:5: note: in expansion of macro 'file'
   98 |     file("task");
      |     ^~~~
#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...