Submission #1093338

# Submission time Handle Problem Language Result Execution time Memory
1093338 2024-09-26T15:19:04 Z InvMOD Cloud Computing (CEOI18_clo) C++14
100 / 100
593 ms 2392 KB
#include<bits/stdc++.h>

using namespace std;

using ll = long long;

template<typename T> bool ckmx(T& a, const T b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T b){if(a > b) return a = b, true; return false;}

const int N = 2e3+5;
const ll INF = 1e18;

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

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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 30 ms 868 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 141 ms 1336 KB Output is correct
8 Correct 37 ms 604 KB Output is correct
9 Correct 237 ms 1880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 396 KB Output is correct
5 Correct 0 ms 464 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 16 ms 576 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 287 ms 1372 KB Output is correct
6 Correct 543 ms 1960 KB Output is correct
7 Correct 490 ms 1960 KB Output is correct
8 Correct 472 ms 1880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 29 ms 860 KB Output is correct
4 Correct 7 ms 348 KB Output is correct
5 Correct 528 ms 1948 KB Output is correct
6 Correct 571 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 30 ms 868 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 141 ms 1336 KB Output is correct
16 Correct 37 ms 604 KB Output is correct
17 Correct 237 ms 1880 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 396 KB Output is correct
22 Correct 0 ms 464 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 16 ms 576 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 287 ms 1372 KB Output is correct
31 Correct 543 ms 1960 KB Output is correct
32 Correct 490 ms 1960 KB Output is correct
33 Correct 472 ms 1880 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 29 ms 860 KB Output is correct
37 Correct 7 ms 348 KB Output is correct
38 Correct 528 ms 1948 KB Output is correct
39 Correct 571 ms 1884 KB Output is correct
40 Correct 47 ms 604 KB Output is correct
41 Correct 99 ms 1028 KB Output is correct
42 Correct 7 ms 348 KB Output is correct
43 Correct 557 ms 2116 KB Output is correct
44 Correct 593 ms 2140 KB Output is correct
45 Correct 534 ms 2392 KB Output is correct
46 Correct 4 ms 348 KB Output is correct
47 Correct 8 ms 348 KB Output is correct
48 Correct 7 ms 348 KB Output is correct