제출 #654095

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

using namespace std;

#define INF 1000000000
#define INFLL 1000000000000000000ll
#define EPS 1e-9
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define fi first
#define sc second
 
using i64 = long long;
using u64 = unsigned long long;
using ld = long double;
using ii = pair<int, int>;	

const int N = 100, M = 1000;

i64 tms[N][N], cost[N][N];
int buy[N][M], sell[N][M];
int n, m, k;

void solve() {
	cin >> n >> m >> k;

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) tms[i][j] = i == j ? 0 : INFLL;
		for(int j = 0; j < k; ++j) cin >> buy[i][j];
		for(int j = 0; j < k; ++j) cin >> sell[i][j];
	}

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

	for(int k = 0; k < n; ++k)
	for(int i = 0; i < n; ++i)
	for(int j = 0; j < n; ++j)
		tms[i][j] = min(tms[i][j], tms[i][k] + tms[k][j]);
	
	int l = 0, r = 1e9 + 1;

	while(l < r) {
		int m = (l + r) / 2;

		for(int i = 0; i < n; ++i)
		for(int j = 0; j < n; ++j)
			cost[i][j] = -INFLL;

		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				for(int l = 0; l < k; ++l) {
					if(i == j || sell[j][l] < 0 || buy[i][l] < 0 || tms[i][j] == INFLL) continue;
					i64 X = sell[j][l] - buy[i][l] - m * tms[i][j];
					cost[i][j] = max(X, cost[i][j]);				
				}
			}
		}

		for(int k = 0; k < n; ++k)
		for(int i = 0; i < n; ++i)
		for(int j = 0; j < n; ++j)
			cost[i][j] = max(cost[i][j], cost[i][k] + cost[k][j]);

		bool ok = false;

		for(int i = 0; i < n; ++i) ok = ok || cost[i][i] >= 0;

		if(!ok) r = m;
		else l = m + 1;
	}

	cout << max(0, r - 1) << '\n';
}	

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
 //	cin >> t;
	while(t--) solve();
	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...