제출 #1303181

#제출 시각아이디문제언어결과실행 시간메모리
1303181dex111222333444555Cloud Computing (CEOI18_clo)C++20
72 / 100
542 ms3724 KiB
#include <bits/stdc++.h> #define all(v) begin(v), end(v) #define siz(v) (int)(v).size() using namespace std; template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;} const int MAXN = 4005, mod = 1e9 + 7, infINT = 1e9 + 23443; const long long inf = 1e18 + 2; struct com{ int c, f, v, id; bool type; com(int _c = 0, int _f = infINT, int _v = 0, int _id = 0, bool _type = 0): c(_c), f(_f), v(_v), id(_id), type(_type) {}; bool operator<(const com &other){ return f > other.f; } }; int numCom, numQuery; long long dp[2][MAXN * 50]; vector<com> vals; void input(){ vals.push_back(com()); cin >> numCom; for(int i = 1; i <= numCom; i++){ int c, f, v; cin >> c >> f >> v; vals.push_back(com(c, f, v, i, 0)); } cin >> numQuery; for(int q = 1; q <= numQuery; q++){ int c, f, v; cin >> c >> f >> v; vals.push_back(com(c, f, v, q, 1)); } } void solve(){ sort(all(vals)); memset(dp[0], -0x3f, sizeof dp[0]); int nxt = 0, cur = 1, cnt = 0; dp[0][0] = 0; for(int i = 0; i < siz(vals) - 1; i++){ swap(cur, nxt); memset(dp[nxt], -0x3f, sizeof dp[nxt]); for(int sum = 0; sum <= cnt * 50; sum++) if (dp[cur][sum] > -inf) { // do not choose maximize(dp[nxt][sum], dp[cur][sum]); // choose nxt if (vals[i + 1].type == 0){ maximize(dp[nxt][sum + vals[i + 1].c], dp[cur][sum] - vals[i + 1].v); } if (vals[i + 1].type == 1 && sum >= vals[i + 1].c){ maximize(dp[nxt][sum - vals[i + 1].c], dp[cur][sum] + vals[i + 1].v); } } cnt += (vals[i + 1].type == 0); } long long res = -inf; for(long long x: dp[nxt]) maximize(res, x); cout << res << '\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "test" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int t = 1; // cin >> t; while(t--){ input(); solve(); } }

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

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