제출 #514031

#제출 시각아이디문제언어결과실행 시간메모리
514031thiago_bastos여행하는 상인 (APIO17_merchant)C++17
0 / 100
30 ms1320 KiB
#include "bits/stdc++.h"

using namespace std;
 
using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned;
using i16 = short;
using u16 = unsigned short;
using ld = long double;
using ii = pair<int, int>;

const int N = 100, K = 1e3, inf = 1e9 + 100;

i64 num[N][N], dem[N][N];
int e[N][N], buy[N][K], dist[N][N], sell[N][K];

void solve() {
	int n, m, p;

	cin >> n >> m >> p;

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < p; ++j) {
			cin >> buy[i][j];
			if(buy[i][j] == -1) buy[i][j] = inf;
		}
		for(int j = 0; j < p; ++j) {
			cin >> sell[i][j];
			if(sell[i][j] == -1) sell[i][j] = -inf;
		}
		for(int j = 0; j < n; ++j) dist[i][j] = inf;
	}

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			if(i == j) continue;
			for(int k = 0; k < p; ++k)
				e[i][j] = max(e[i][j], sell[j][k] - buy[i][k]);
		}
	}

	for(int i = 0; i < m; ++i) {
		int u, v, w;
		cin >> u >> v >> w;
		--u, --v;
		dist[u][v] = w;
	}

	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) {
			num[i][j] = e[i][j];
			dem[i][j] = dist[i][j];
		}
	}

	for(int k = 0; k < n; ++k) {
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				i64 P = num[i][j], Q = dem[i][j];
				i64 R = num[i][k] + num[k][j], S = dem[i][k] + dem[k][j];
				if((double)P / Q <= (double)R / S || P + R == 0 && Q > S)
					num[i][j] = R, dem[i][j] = S;
			}
		}
	}

	i64 ans = 0;
	for(int i = 0; i < n; ++i) ans = max(ans, num[i][i] / dem[i][i]);
	cout << ans << '\n';
}
 
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) solve();
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

merchant.cpp: In function 'void solve()':
merchant.cpp:68:53: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   68 |     if((double)P / Q <= (double)R / S || P + R == 0 && Q > S)
      |                                          ~~~~~~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...