제출 #101038

#제출 시각아이디문제언어결과실행 시간메모리
101038oolimry여행하는 상인 (APIO17_merchant)C++14
100 / 100
140 ms4284 KiB
#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; static long long buy[105][1005]; static long long sell[105][1005]; static long long dist[105][105]; static long long profit[105][105]; 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 static long long diff[105][105]; 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...