Submission #1093334

#TimeUsernameProblemLanguageResultExecution timeMemory
1093334InvMODCloud Computing (CEOI18_clo)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; template<typename T> ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;} template<typename T> ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;} const int N = 2e3+5; const ll INF = 1e9; struct Computer{ int core, rate; ll value; // computer will < 0 and task will > 0 // computer has no harm with our dynamic programing :D bool operator < (const Computer& q) const{ if(rate != q.rate){ return rate > q.rate; } else return value < q.value; } }; int n, m; ll dp[2][50 * N]; Computer value[2 * N]; void solve() { cin >> n; int total_core = 0; for(int i = 1; i <= n; i++){ cin >> value[i].core >> value[i].rate >> value[i].value; value[i].value = -value[i].value; total_core = total_core + value[i].core; } cin >> m; for(int i = n+1; i <= n+m; i++){ cin >> value[i].core >> value[i].rate >> value[i].value; value[i].core = -value[i].core; } sort(value+1, value+1+n+m); for(int i = 0; i < 2; i++){ fill(dp[i]+1, dp[i]+1+total_core, -INF); } for(int i = 1; i <= n+m; i++){ int pos = (i&1), pre = ((i&1)^1); if(value[i].core > 0){ // is computer //cout << value[i].core <<" " << value[i].value <<"\n"; for(int j = value[i].core; j <= total_core; j++){ ckmx(dp[pos][j], dp[pre][j - value[i].core] + value[i].value); } } else{ // is task int cur_core = -value[i].core; //cout << cur_core << " " << value[i].value <<"\n"; for(int j = total_core - cur_core; j >= 0; j--){ ckmx(dp[pos][j], dp[pre][j + cur_core] + value[i].value); } } for(int j = 0; j <= total_core; j++){ ckmx(dp[pos][j], dp[pre][j]); } } ll answer = 0; for(int i = 0; i < 2; i++){ for(int j = 0; j <= total_core; j++){ answer = max(answer, dp[i][j]); } } cout << answer <<"\n"; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP", "r", stdin); freopen(name".OUT", "w", stdout); } solve(); return 0; }

Compilation message (stderr)

clo.cpp:7:22: error: ISO C++ forbids declaration of 'ckmx' with no type [-fpermissive]
    7 | template<typename T> ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
      |                      ^~~~
clo.cpp:8:22: error: ISO C++ forbids declaration of 'ckmn' with no type [-fpermissive]
    8 | template<typename T> ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}
      |                      ^~~~
clo.cpp: In function 'int32_t main()':
clo.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(name".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~