Submission #128374

# Submission time Handle Problem Language Result Execution time Memory
128374 2019-07-10T19:57:33 Z keko37 Travelling Merchant (APIO17_merchant) C++14
66 / 100
175 ms 4216 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long llint;

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

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

void ispis () {
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) {
            cout << g[i][j] << " ";
        }
        cout << endl;
    }
}

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];
        }
    }
    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*INF) cost[i][j] = -INF*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 = 1000000001;
    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 127 ms 3576 KB Output is correct
2 Correct 97 ms 1400 KB Output is correct
3 Correct 70 ms 1480 KB Output is correct
4 Correct 13 ms 888 KB Output is correct
5 Correct 13 ms 888 KB Output is correct
6 Correct 13 ms 888 KB Output is correct
7 Correct 13 ms 888 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 10 ms 888 KB Output is correct
10 Correct 15 ms 888 KB Output is correct
11 Correct 13 ms 888 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 14 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 888 KB Output is correct
2 Correct 14 ms 888 KB Output is correct
3 Correct 14 ms 888 KB Output is correct
4 Correct 13 ms 888 KB Output is correct
5 Correct 19 ms 888 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 14 ms 888 KB Output is correct
8 Correct 14 ms 1016 KB Output is correct
9 Correct 14 ms 1016 KB Output is correct
10 Correct 15 ms 888 KB Output is correct
11 Correct 16 ms 1016 KB Output is correct
12 Correct 16 ms 1016 KB Output is correct
13 Correct 15 ms 888 KB Output is correct
14 Correct 16 ms 888 KB Output is correct
15 Correct 16 ms 988 KB Output is correct
16 Correct 13 ms 1016 KB Output is correct
17 Correct 21 ms 1016 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 22 ms 1020 KB Output is correct
20 Correct 16 ms 892 KB Output is correct
21 Correct 16 ms 1016 KB Output is correct
22 Correct 13 ms 1016 KB Output is correct
23 Correct 15 ms 888 KB Output is correct
24 Correct 13 ms 888 KB Output is correct
25 Correct 13 ms 888 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 10 ms 888 KB Output is correct
28 Correct 15 ms 888 KB Output is correct
29 Correct 13 ms 888 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 14 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 127 ms 1780 KB Output is correct
2 Correct 175 ms 3960 KB Output is correct
3 Correct 111 ms 1632 KB Output is correct
4 Correct 139 ms 1784 KB Output is correct
5 Correct 130 ms 1784 KB Output is correct
6 Correct 82 ms 1588 KB Output is correct
7 Correct 21 ms 1016 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 22 ms 1020 KB Output is correct
10 Correct 16 ms 892 KB Output is correct
11 Correct 16 ms 1016 KB Output is correct
12 Correct 13 ms 1016 KB Output is correct
13 Correct 15 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 888 KB Output is correct
2 Correct 14 ms 888 KB Output is correct
3 Correct 14 ms 888 KB Output is correct
4 Correct 13 ms 888 KB Output is correct
5 Correct 19 ms 888 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 14 ms 888 KB Output is correct
8 Correct 14 ms 1016 KB Output is correct
9 Correct 14 ms 1016 KB Output is correct
10 Correct 15 ms 888 KB Output is correct
11 Correct 16 ms 1016 KB Output is correct
12 Correct 16 ms 1016 KB Output is correct
13 Correct 15 ms 888 KB Output is correct
14 Correct 16 ms 888 KB Output is correct
15 Correct 16 ms 988 KB Output is correct
16 Correct 13 ms 1016 KB Output is correct
17 Correct 127 ms 1780 KB Output is correct
18 Correct 175 ms 3960 KB Output is correct
19 Correct 111 ms 1632 KB Output is correct
20 Correct 139 ms 1784 KB Output is correct
21 Correct 130 ms 1784 KB Output is correct
22 Correct 82 ms 1588 KB Output is correct
23 Correct 21 ms 1016 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 22 ms 1020 KB Output is correct
26 Correct 16 ms 892 KB Output is correct
27 Correct 16 ms 1016 KB Output is correct
28 Correct 13 ms 1016 KB Output is correct
29 Correct 15 ms 888 KB Output is correct
30 Correct 80 ms 1488 KB Output is correct
31 Correct 81 ms 1656 KB Output is correct
32 Correct 102 ms 2820 KB Output is correct
33 Correct 86 ms 1656 KB Output is correct
34 Correct 89 ms 1656 KB Output is correct
35 Correct 89 ms 1748 KB Output is correct
36 Correct 130 ms 4216 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 2 ms 504 KB Output is correct
39 Correct 85 ms 1400 KB Output is correct
40 Incorrect 85 ms 1528 KB Output isn't correct
41 Halted 0 ms 0 KB -