Submission #161838

# Submission time Handle Problem Language Result Execution time Memory
161838 2019-11-04T15:57:46 Z Minnakhmetov Travelling Merchant (APIO17_merchant) C++14
0 / 100
1000 ms 10616 KB
#include <bits/stdc++.h>
    
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
 
using namespace std;

const int N = 51, C = 1000, INF = 2e9;
int dp[C][N][N], b[N][N], s[N][N], w[N][N];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            w[i][j] = INF;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            cin >> b[i][j] >> s[i][j];
        }
    }

    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        w[a][b] = min(w[a][b], c);
    }

    int ans = 0;

    for (int i = 0; i < n; i++) {
        for (int x = 0; x < C; x++) {
            for (int y = 0; y < n; y++) {
                for (int z = 0; z <= k; z++) {
                    dp[x][y][z] = -INF;
                }
            }
        }

        dp[0][i][0] = 0;

        for (int x = 0; x < C; x++) {
            for (int y = 0; y < n; y++) {
                if (dp[x][y][0] != -INF) {
                    for (int z = 1; z <= k; z++) {
                        if (b[y][z] != -1) {
                            dp[x][y][z] = max(dp[x][y][z], 
                                dp[x][y][0] - b[y][z]);
                        }
                    }
                }

                for (int z = 0; z <= k; z++) {
                    if (dp[x][y][z] != -INF) {
                        for (int to = 0; to < n; to++) {
                            if (w[y][to] != INF && x + w[y][to] < C) {
                                dp[x + w[y][to]][to][z] = max(dp[x + w[y][to]][to][z], 
                                    dp[x][y][z]);
                                if (z != 0 && s[to][z] != -1) {
                                    dp[x + w[y][to]][to][0] = max(dp[x + w[y][to]][to][0], 
                                        dp[x][y][z] + s[to][z]);
                                }
                            }
                        }
                    }
                }
            }
        }

        for (int x = 1; x < C; x++) {
            // cout << x << " " << i << " " << dp[x][i][0] << "\n";
            ans = max(ans, dp[x][i][0] / x);
        }

    }

    cout << ans << "\n";


    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 10616 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 262 ms 10488 KB Output is correct
2 Correct 125 ms 10536 KB Output is correct
3 Incorrect 531 ms 10616 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 10488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 262 ms 10488 KB Output is correct
2 Correct 125 ms 10536 KB Output is correct
3 Incorrect 531 ms 10616 KB Output isn't correct
4 Halted 0 ms 0 KB -