| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 50747 | ayhcbagnop | Travelling Merchant (APIO17_merchant) | C++14 | 126 ms | 1676 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Power Of Ninja Go
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector< ii > vii;
#define X first
#define Y second
#define pb push_back
const int maxn = 105;
const int maxk = 1005;
int dist[maxn][maxn];
int buy[maxn][maxk];
int sell[maxn][maxk];
ll prof[maxn][maxn];
ll aug[maxn][maxn];
int n, m, k;
bool works(ll x)
{
    //printf("x = %lld\n", x);
    for(int i = 1; i<= n; i++)
    {
        for(int j = 1; j<= n; j++)
        {
            aug[i][j] = 1LL*x*dist[i][j] - prof[i][j];
            //printf("aug[%d][%d] = %lld\n", i, j, aug[i][j]);
        }
    }
    for(int k = 1; k<= n; k++) for(int i = 1; i<= n; i++) for(int j = 1; j<= n; j++)
        aug[i][j] = min(aug[i][j], aug[i][k]+aug[k][j]);
    for(int i = 1; i<= n; i++) if(aug[i][i]<= 0) return true;
    return false;
}
int main()
{
    scanf("%d %d %d", &n, &m, &k);
    for(int i = 1; i<= n; i++) for(int j = 1; j<= n; j++) dist[i][j] = 1e9;
    for(int i = 1; i<= n; i++)
    {
        for(int j = 1; j<= k; j++) scanf("%d %d", &buy[i][j], &sell[i][j]);
    }
    while(m--)
    {
        int u, v, w; scanf("%d %d %d", &u, &v, &w);
        dist[u][v] = min(dist[u][v], w);
    }
    for(int k = 1; k<= n; k++) for(int i = 1; i<= n; i++) for(int j = 1; j<= n; j++) dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
    for(int i = 1; i<= n; i++) for(int j = 1; j<= n; j++) prof[i][j] = 0;
    for(int i = 1; i<= n; i++)
    {
        for(int j = 1; j<= n; j++)
        {
            for(int prod = 1; prod<= k; prod++)
            {
                if(buy[i][prod] == -1 || sell[j][prod] == -1) continue;
                prof[i][j] = max(prof[i][j], 1LL*sell[j][prod]-buy[i][prod]);
            }
            //printf("prof[%d][%d] = %lld\n", i, j, prof[i][j]);
        }
    }
    ll lo = 0, hi = 1e9;
    while(lo< hi)
    {
        ll mid = (lo+hi+1)/2;
        if(works(mid)) lo = mid;
        else hi = mid-1;
    }
    printf("%lld\n", lo);
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
