Submission #533443

# Submission time Handle Problem Language Result Execution time Memory
533443 2022-03-06T04:58:34 Z ohohorz Travelling Merchant (APIO17_merchant) C++14
0 / 100
18 ms 3140 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define f first
// #define s second
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define vi vector<int>

const int N = 100 + 5;
const int INF = 1e18;
const int MOD = 998244353;
const int BLOCKSZ = 318;
const int K = 1005;

int binpow(int a, int b){
    if(b == 0) return 1;
    if(b%2==0){
        int x = binpow(a, b >> 1LL);
        return (x%MOD*x%MOD)%MOD;
    }
    int x = binpow(a, b - 1);
    return (x%MOD*a%MOD)%MOD;
}
int b[N][K], s[N][K],dist[N][N];

void solve(){
    
    int n, m, k;
    cin >> n >> m >> k;
    for(int i =1;i<=n;i++){
        for(int j =1;j<=k;j++) cin >> b[i][j];
        for(int j =1;j<=k;j++) cin >> s[i][j];
    }
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=n;j++){
            dist[i][j] = INF;
        }
        dist[i][i] = 0;
    }
    for(int i =1;i<=m;i++){
        int u, v, d;
        cin >> u >> v >> d;
        dist[u][v] = d;
    }
    for(int k = 1;k <= n;k++){
        for(int i = 1;i <= n;i++){
            for(int j = 1;j <= n;j++){
                if(dist[i][k] < INF and dist[k][j] < INF)
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    pii best;// {profit, path length}
    best = mp(-INF, -INF);
    bool first = 1;
    for(int i = 2;i <= n;i++){
        if(dist[1][i] == INF or dist[i][1] == INF) continue;
        int path = dist[1][i] + dist[i][1];
        int profit = -INF;
        for(int j =1;j<=k;j++){
            profit = max(s[i][j] - b[1][j], profit);
        }
        if(first == 1){
            best = mp(profit, path);
            first =0;
        }else{
            if( (profit * best.second) > (path * best.first))
                best = mp(profit, path);
        }

    }
    cout << max(0LL, best.f / best.second);




}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(0);
    
    int tc=1;
    // cin >> tc;
    while(tc--){
        solve();
    }

    
    

}
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 3140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 708 KB Output isn't correct
2 Halted 0 ms 0 KB -