Submission #101035

# Submission time Handle Problem Language Result Execution time Memory
101035 2019-03-16T05:51:25 Z oolimry Travelling Merchant (APIO17_merchant) C++14
0 / 100
118 ms 3764 KB
#include <bits/stdc++.h>

using namespace std;

long long inf = 1000000000000000ll;
int main()
{
    int n, m, t;
    //freopen("i.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m >> t;

    long long buy[n][t];
    long long sell[n][t];
    long long dist[n][n];
    long long profit[n][n];

    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            buy[i][j] = inf;
            sell[i][j] = inf;
            profit[i][j] = 0;
            dist[i][j] = inf;
        }
    }
    for(int i = 0;i < n;i++){
        for(int k = 0;k < t;k++){
            cin >> buy[i][k];

            cin >> sell[i][k];
        }
    }



    ///Max Profit btw two nodes
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            for(int k = 0;k < t;k++){
                if(buy[i][k] != -1 && sell[j][k] != -1)
                    profit[i][j] = max(profit[i][j],sell[j][k] -  buy[i][k]);

            }
        }
    }

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

    ///Floyd
    for(int k = 0;k < n;k++){
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            //cout << profit[i][j] << " ";
        }
       // cout << "\n";
    }

    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            //cout << dist[i][j] << " ";
        }
       // cout << "\n";
    }

    ///p/d >= v
    ///p - dv >= 0 for a cycle, where p is total profit, d is total distance
    ///monotonous in terms of v
    long long diff[n][n];

    long long low = 0ll;
    long long high = inf;
    while(true){
        if(low == high - 1) break;
        long long v = (low + high) / 2ll;
        //v = 2;

        for(int i =0 ;i < n;i++){
            for(int j = 0;j < n;j++){
                //if(dist[i][j] == inf) diff[i][j] = -1ll*inf;
                diff[i][j] = profit[i][j] - v * min(inf/v,dist[i][j]);
                //cout << diff[i][j] << " ";
            }
            //cout << "\n";
        }

        for(int k = 0;k < n;k++){
            for(int i = 0;i < n;i++){
                for(int j = 0;j < n;j++){
                    diff[i][j] = max(diff[i][j], diff[i][k] + diff[k][j]);

                }
            }
        }

        for(int i =0 ;i < n;i++){
            for(int j = 0;j < n;j++){
                //if(dist[i][j] == inf) diff[i][j] = -1ll*inf;
                //diff[i][j] = profit[i][j] - v * min(inf/v,dist[i][j]);
                //cout << diff[i][j] << " ";
            }
            //cout << "\n";
        }

        bool can = false;
        for(int i = 0;i < n;i++){
           // cout << diff[i][i] << "\n";
            if(diff[i][i] >= 0){
                can = true;
                break;
            }
        }
        if(can) low = v;
        else high = v;

        //break;
    }

    cout << low;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 90 ms 3424 KB Output is correct
2 Runtime error 3 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 71 ms 924 KB Output is correct
2 Correct 118 ms 3764 KB Output is correct
3 Runtime error 4 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -