Submission #786392

#TimeUsernameProblemLanguageResultExecution timeMemory
786392PenguinsAreCuteTravelling Merchant (APIO17_merchant)C++17
100 / 100
98 ms4240 KiB
// editorial exists
// also i like 42
// so im adding comments to make it 42 lines
// yay 42 lines :)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stMx(a,b) a = max(a,b)
#define stMn(a,b) a = min(a,b)
#define BIGNO (int)1210201069
#define REP(i, a, b) for(int i = a; i < b; i++)
int32_t main() {
    int n, m, K, v, w, t; cin >> n >> m >> K;
    int B[n][K], S[n][K], time[n][n], profit[n][n], relprofit[n][n];
    REP(i, 0, n) REP(j, 0, n) {
        time[i][j] = BIGNO; profit[i][j] = 0;
    }
    REP(i, 0, n) REP(j, 0, K) {
        cin >> B[i][j] >> S[i][j];
        if(B[i][j] == -1) B[i][j] = BIGNO;
    }
    REP(i, 0, m) {
        cin >> v >> w >> t; v--; w--;
        time[v][w] = t;
    }
    REP(i, 0, n) time[i][i] = 0;
    REP(k, 0, n) REP(i, 0, n) REP(j, 0, n) stMn(time[i][j], time[i][k] + time[k][j]);
    REP(i, 0, n) REP(j, 0, n) REP(k, 0, K) stMx(profit[i][j], S[j][k] - B[i][k]);
    int l = 0, h = 1000000001;
    while(h - l > 1) {
        int mid = (l + h) / 2;
        REP(i, 0, n) REP(j, 0, n) {
            relprofit[i][j] = profit[i][j] - time[i][j] * mid;
            if(i == j && profit[i][i] == 0 && relprofit[i][i] == 0) relprofit[i][i] = -1;
        }
        REP(k, 0, n) REP(i, 0, n) REP(j, 0, n) stMx(relprofit[i][j], relprofit[i][k] + relprofit[k][j]);
        bool nonnegcycle = false; REP(i, 0, n) if(relprofit[i][i] >= 0) nonnegcycle = true;
        if(nonnegcycle) l = mid;
        else h = mid;
    }
    cout << l;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...