답안 #57288

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57288 2018-07-14T13:26:02 Z gabrielsimoes 여행하는 상인 (APIO17_merchant) C++17
0 / 100
89 ms 58608 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
// const int MAXN = 101, MAXM = 9901, MAXK = 1001;
const int MAXN = 51, MAXK = 51;
const ll INF = 1e15;

int N, M, K;
vector<pii> g[MAXN];
int buy[MAXN][MAXK];
int sell[MAXN][MAXK];

// ll dist[2][MAXN];
// priority_queue<pair<int, ll>, vector<pair<int, ll>>, greater<pair<int, ll>>> q;
// void dijkstra(int start, ll d[], vector<pii> g[]) {
//     for (int i = 1; i <= N; i++) d[i] = INF;
//     q.push({0, start});
//     d[start] = 0;

//     while (!q.empty()) {
//         ll dd; int cur;
//         tie(dd, cur) = q.top();
//         q.pop();
//         if (dd > d[cur]) continue;
//         for (pii p : g[cur]) {
//             int nx = p.first;
//             ll cost = p.second;

//             if (dd + cost < d[nx]) {
//                 d[nx] = dd + cost;
//                 q.push({d[nx], nx});
//             }
//         }
//     }
// }

ll dp[MAXN][MAXN*MAXN][MAXK];
bool ok[MAXN][MAXN*MAXN][MAXK];

ll f(int cur, int sum, int bag) {
    if (cur == 1 && sum == 0 && bag == 0) return 0;
    else if (sum <= 0) return -INF;

    ll &ret = dp[cur][sum][bag];
    if (ok[cur][sum][bag]) return ret;
    ok[cur][sum][bag] = true;
    ret = -INF;

    if (bag && sell[cur][bag] != -1) {
        ret = max(ret, f(cur, sum, 0) + sell[cur][bag]);
    }

    if (bag == 0) {
        for (int k = 1; k <= K; k++) {
            if (buy[cur][k] != -1) {
                ret = max(ret, f(cur, sum, k) - buy[cur][k]);
            }
        }
    }

    for (pii p : g[cur]) {
        int nx = p.first;
        int cost = p.second;

        ret = max(ret, f(nx, sum - cost, bag));
    }

    return ret;
}

int main() {
    scanf("%d%d%d", &N, &M, &K);
    for (int i = 1; i <= N; i++) {
        for (int k = 1; k <= K; k++) {
            scanf("%d%d", &buy[i][k], &sell[i][k]);
        }
    }

    for (int i = 1,a,b,c; i <= M; i++) {
        scanf("%d%d%d", &a, &b, &c);
        g[a].push_back({b, c});
    }

    ll ans = 0;
    for (int sum = 1; sum <= MAXN*MAXN; sum++) {
        ans = max(ans, f(1, sum, 0)/ll(sum));
    }

    printf("%lld\n", ans);
}

Compilation message

merchant.cpp: In function 'int main()':
merchant.cpp:74:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &N, &M, &K);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:77:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d", &buy[i][k], &sell[i][k]);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &a, &b, &c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 58608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6 ms 58608 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 58608 KB Output isn't correct
2 Halted 0 ms 0 KB -