Submission #124767

# Submission time Handle Problem Language Result Execution time Memory
124767 2019-07-03T22:15:09 Z eriksuenderhauf Cloud Computing (CEOI18_clo) C++11
100 / 100
801 ms 2168 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ni(n) scanf("%d\n", &(n))
#define prl(n) printf("%lld\n", (n))
using namespace std;
typedef long long ll;
const ll INF = 1e18 + 7;
const int MAXN = 1e5 + 5;
struct order {
    int c, f, v;
    bool operator<(const order &rhs) const {
        if (f == rhs.f)
            return c > rhs.c;
        return f > rhs.f;
    }
} b[4005];
ll dp[2][MAXN];

int main()
{
    int n, m;
    ni(n);
    for (int i = 0; i < n; i++) { // cores, frequency, value
        scanf("%d %d %d", &b[i].c, &b[i].f, &b[i].v);
        b[i].v *= -1;
    }
    ni(m);
    for (int i = n; i < n + m; i++) { // cores, frequency, value
        scanf("%d %d %d", &b[i].c, &b[i].f, &b[i].v);
        b[i].c *= -1;
    }
    sort(b, b + n + m);
    fill(dp[0], dp[0] + MAXN, -INF);
    dp[0][0] = 0;
    ll ans = 0;
    for (int i = 0; i < n + m; i++) {
        for (int j = 0; j < MAXN; j++) {
            dp[(i&1)^1][j] = dp[i&1][j];
            if (j >= b[i].c && j - b[i].c < MAXN) {
                // max value if you have j cores left after
                // processing first i queries
                dp[(i&1)^1][j] = max(dp[i&1][j], dp[i&1][j - b[i].c] + b[i].v);
            }
        }
    }
    prl(*max_element(dp[((n+m-1)&1)^1], dp[((n+m-1)&1)^1] + MAXN));
    return 0;
}

Compilation message

clo.cpp: In function 'int main()':
clo.cpp:35:8: warning: unused variable 'ans' [-Wunused-variable]
     ll ans = 0;
        ^~~
clo.cpp:3:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ni(n) scanf("%d\n", &(n))
               ~~~~~^~~~~~~~~~~~~~
clo.cpp:22:5: note: in expansion of macro 'ni'
     ni(n);
     ^~
clo.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &b[i].c, &b[i].f, &b[i].v);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:3:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ni(n) scanf("%d\n", &(n))
               ~~~~~^~~~~~~~~~~~~~
clo.cpp:27:5: note: in expansion of macro 'ni'
     ni(m);
     ^~
clo.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &b[i].c, &b[i].f, &b[i].v);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2012 KB Output is correct
2 Correct 3 ms 1912 KB Output is correct
3 Correct 25 ms 1912 KB Output is correct
4 Correct 44 ms 1908 KB Output is correct
5 Correct 384 ms 2012 KB Output is correct
6 Correct 389 ms 1912 KB Output is correct
7 Correct 411 ms 2012 KB Output is correct
8 Correct 404 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1912 KB Output is correct
2 Correct 5 ms 1912 KB Output is correct
3 Correct 24 ms 2040 KB Output is correct
4 Correct 25 ms 2040 KB Output is correct
5 Correct 185 ms 1912 KB Output is correct
6 Correct 185 ms 1984 KB Output is correct
7 Correct 401 ms 2032 KB Output is correct
8 Correct 405 ms 1912 KB Output is correct
9 Correct 391 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1912 KB Output is correct
2 Correct 10 ms 1912 KB Output is correct
3 Correct 40 ms 1968 KB Output is correct
4 Correct 39 ms 1912 KB Output is correct
5 Correct 76 ms 1912 KB Output is correct
6 Correct 77 ms 1972 KB Output is correct
7 Correct 105 ms 1912 KB Output is correct
8 Correct 103 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1912 KB Output is correct
2 Correct 6 ms 1912 KB Output is correct
3 Correct 304 ms 1912 KB Output is correct
4 Correct 364 ms 2040 KB Output is correct
5 Correct 753 ms 2040 KB Output is correct
6 Correct 801 ms 2040 KB Output is correct
7 Correct 798 ms 2040 KB Output is correct
8 Correct 782 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1912 KB Output is correct
2 Correct 35 ms 1912 KB Output is correct
3 Correct 166 ms 1912 KB Output is correct
4 Correct 401 ms 1912 KB Output is correct
5 Correct 793 ms 2168 KB Output is correct
6 Correct 798 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2012 KB Output is correct
2 Correct 3 ms 1912 KB Output is correct
3 Correct 25 ms 1912 KB Output is correct
4 Correct 44 ms 1908 KB Output is correct
5 Correct 384 ms 2012 KB Output is correct
6 Correct 389 ms 1912 KB Output is correct
7 Correct 411 ms 2012 KB Output is correct
8 Correct 404 ms 2040 KB Output is correct
9 Correct 4 ms 1912 KB Output is correct
10 Correct 5 ms 1912 KB Output is correct
11 Correct 24 ms 2040 KB Output is correct
12 Correct 25 ms 2040 KB Output is correct
13 Correct 185 ms 1912 KB Output is correct
14 Correct 185 ms 1984 KB Output is correct
15 Correct 401 ms 2032 KB Output is correct
16 Correct 405 ms 1912 KB Output is correct
17 Correct 391 ms 2040 KB Output is correct
18 Correct 10 ms 1912 KB Output is correct
19 Correct 10 ms 1912 KB Output is correct
20 Correct 40 ms 1968 KB Output is correct
21 Correct 39 ms 1912 KB Output is correct
22 Correct 76 ms 1912 KB Output is correct
23 Correct 77 ms 1972 KB Output is correct
24 Correct 105 ms 1912 KB Output is correct
25 Correct 103 ms 1912 KB Output is correct
26 Correct 6 ms 1912 KB Output is correct
27 Correct 6 ms 1912 KB Output is correct
28 Correct 304 ms 1912 KB Output is correct
29 Correct 364 ms 2040 KB Output is correct
30 Correct 753 ms 2040 KB Output is correct
31 Correct 801 ms 2040 KB Output is correct
32 Correct 798 ms 2040 KB Output is correct
33 Correct 782 ms 2040 KB Output is correct
34 Correct 4 ms 1912 KB Output is correct
35 Correct 35 ms 1912 KB Output is correct
36 Correct 166 ms 1912 KB Output is correct
37 Correct 401 ms 1912 KB Output is correct
38 Correct 793 ms 2168 KB Output is correct
39 Correct 798 ms 1912 KB Output is correct
40 Correct 207 ms 1988 KB Output is correct
41 Correct 387 ms 2040 KB Output is correct
42 Correct 614 ms 2040 KB Output is correct
43 Correct 799 ms 2040 KB Output is correct
44 Correct 799 ms 2040 KB Output is correct
45 Correct 801 ms 2040 KB Output is correct
46 Correct 401 ms 2040 KB Output is correct
47 Correct 603 ms 1912 KB Output is correct
48 Correct 588 ms 2040 KB Output is correct