Submission #128399

# Submission time Handle Problem Language Result Execution time Memory
128399 2019-07-10T21:37:04 Z keko37 Travelling Merchant (APIO17_merchant) C++14
66 / 100
168 ms 3064 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long llint;

const int MAXN = 105;
const int MAXP = 1005;
const llint INF = 3000000000000000LL;

llint n, m, p;
llint buy[MAXN][MAXP], sell[MAXN][MAXP];
llint d[MAXN][MAXN], g[MAXN][MAXN];
llint cost[MAXN][MAXN];

bool moze (llint t) {
    if (t == 0) return 1;
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) {
            cost[i][j] = t * d[i][j] - g[i][j];
            if (d[i][j] == INF) cost[i][j] = INF;
        }
    }
    for (int k=1; k<=n; k++) {
        for (int i=1; i<=n; i++) {
            for (int j=1; j<=n; j++) {
                if (cost[i][k] + cost[k][j] < cost[i][j]) {
                    cost[i][j] = cost[i][k] + cost[k][j];
                }
                if (cost[i][j] < -INF) cost[i][j] = -INF;
            }
        }
    }
    for (int i=1; i<=n; i++) {
        if (cost[i][i] <= 0) return 1;
    }
    return 0;
}

void precompute () {
    for (int k=1; k<=n; k++) {
        for (int i=1; i<=n; i++) {
            for (int j=1; j<=n; j++) {
                if (d[i][k] + d[k][j] < d[i][j]) {
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) {
            llint res = 0;
            for (int k=1; k<=p; k++) {
                res = max(res, sell[j][k] - buy[i][k]);
            }
            g[i][j] = res;
        }
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> p;
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=p; j++) {
            cin >> buy[i][j] >> sell[i][j];
            if (buy[i][j] == -1) buy[i][j] = INF;
            if (sell[i][j] == -1) sell[i][j] = -INF;
        }
    }
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) {
            d[i][j] = INF;
        }
    }
    for (int i=1; i<=m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        d[a][b] = c;
    }
    precompute();
    llint lo = 0, hi = 1000000005;
    while (lo < hi) {
        llint mid = (lo + hi + 1) / 2;
        if (moze(mid)) {
            lo = mid;
        } else {
            hi = mid-1;
        }
    }
    cout << lo;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 82 ms 3064 KB Output is correct
2 Correct 49 ms 1400 KB Output is correct
3 Correct 52 ms 1400 KB Output is correct
4 Correct 10 ms 888 KB Output is correct
5 Correct 9 ms 888 KB Output is correct
6 Correct 9 ms 888 KB Output is correct
7 Correct 11 ms 1016 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 9 ms 888 KB Output is correct
10 Correct 10 ms 888 KB Output is correct
11 Correct 10 ms 888 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 10 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 888 KB Output is correct
2 Correct 9 ms 888 KB Output is correct
3 Correct 10 ms 888 KB Output is correct
4 Correct 9 ms 888 KB Output is correct
5 Correct 17 ms 888 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 10 ms 892 KB Output is correct
8 Correct 10 ms 888 KB Output is correct
9 Correct 10 ms 948 KB Output is correct
10 Correct 10 ms 888 KB Output is correct
11 Correct 13 ms 1020 KB Output is correct
12 Correct 12 ms 1016 KB Output is correct
13 Correct 10 ms 892 KB Output is correct
14 Correct 12 ms 888 KB Output is correct
15 Correct 13 ms 1016 KB Output is correct
16 Correct 9 ms 940 KB Output is correct
17 Correct 20 ms 1016 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 20 ms 1016 KB Output is correct
20 Correct 14 ms 1016 KB Output is correct
21 Correct 13 ms 1016 KB Output is correct
22 Correct 11 ms 888 KB Output is correct
23 Correct 11 ms 888 KB Output is correct
24 Correct 9 ms 888 KB Output is correct
25 Correct 11 ms 1016 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 9 ms 888 KB Output is correct
28 Correct 10 ms 888 KB Output is correct
29 Correct 10 ms 888 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 10 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 1784 KB Output is correct
2 Correct 168 ms 3048 KB Output is correct
3 Correct 111 ms 1592 KB Output is correct
4 Correct 136 ms 1832 KB Output is correct
5 Correct 124 ms 1836 KB Output is correct
6 Correct 69 ms 1532 KB Output is correct
7 Correct 20 ms 1016 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 20 ms 1016 KB Output is correct
10 Correct 14 ms 1016 KB Output is correct
11 Correct 13 ms 1016 KB Output is correct
12 Correct 11 ms 888 KB Output is correct
13 Correct 11 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 888 KB Output is correct
2 Correct 9 ms 888 KB Output is correct
3 Correct 10 ms 888 KB Output is correct
4 Correct 9 ms 888 KB Output is correct
5 Correct 17 ms 888 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 10 ms 892 KB Output is correct
8 Correct 10 ms 888 KB Output is correct
9 Correct 10 ms 948 KB Output is correct
10 Correct 10 ms 888 KB Output is correct
11 Correct 13 ms 1020 KB Output is correct
12 Correct 12 ms 1016 KB Output is correct
13 Correct 10 ms 892 KB Output is correct
14 Correct 12 ms 888 KB Output is correct
15 Correct 13 ms 1016 KB Output is correct
16 Correct 9 ms 940 KB Output is correct
17 Correct 125 ms 1784 KB Output is correct
18 Correct 168 ms 3048 KB Output is correct
19 Correct 111 ms 1592 KB Output is correct
20 Correct 136 ms 1832 KB Output is correct
21 Correct 124 ms 1836 KB Output is correct
22 Correct 69 ms 1532 KB Output is correct
23 Correct 20 ms 1016 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 20 ms 1016 KB Output is correct
26 Correct 14 ms 1016 KB Output is correct
27 Correct 13 ms 1016 KB Output is correct
28 Correct 11 ms 888 KB Output is correct
29 Correct 11 ms 888 KB Output is correct
30 Correct 57 ms 1484 KB Output is correct
31 Correct 57 ms 1720 KB Output is correct
32 Correct 76 ms 2700 KB Output is correct
33 Correct 54 ms 1656 KB Output is correct
34 Correct 56 ms 1784 KB Output is correct
35 Correct 54 ms 1656 KB Output is correct
36 Correct 124 ms 3044 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 54 ms 1528 KB Output is correct
40 Incorrect 50 ms 1656 KB Output isn't correct
41 Halted 0 ms 0 KB -