Submission #231938

# Submission time Handle Problem Language Result Execution time Memory
231938 2020-05-15T11:30:30 Z Atalasion Travelling Merchant (APIO17_merchant) C++14
12 / 100
412 ms 2432 KB
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-O2")
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 100 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 2000000000000000010;
const ll LOG = 25;

int n, m, K, B[N][N * 10], S[N][N * 10];
ll dis[N][N], pth[N][N], D[N];
vector<pair<int, ll>> G[N];

bool relax(int v, int u, ll w){
	//cout << v << ' ' << u << ' ' << w << ' ' << D[v] << ' ' << D[u] << '\n';
	if (D[u] > D[v] + w){
		D[u] = D[v] + w;
		return 1;
	}
	return 0;
}

bool isval(ll x){
	for (int i = 1; i <= n; i++) G[i].clear();
	for (int i = 0; i < N; i++) D[i] = INF;
	D[1] = 0;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			if (i == j) continue;
			if (dis[i][j] == INF) continue;
			ll W = INF / x;
			ll Z;
			if (W < dis[i][j]) Z = INF;
			else Z = x * dis[i][j] - pth[i][j];
			G[i].pb({j, Z});
//			cout << i << ' ' << j << ' ' << x * dis[i][j] - pth[i][j] << '\n';
		}
	}
	for (int i = 1; i <= 2 * n; i++){
		bool f = 0;
		for (int j = 1; j <= n; j++){
			for (auto u:G[j]){
				f |= ((dis[u.F][1] != INF) && relax(j, u.F, u.S));
//				if (relax(j, u.F, u.S) && i >= n + 1 && dis[u.F][1] != INF) return 1;
			}
		}
		if (f && i == 2 * n) return 1;
	}
	//cout << "Fuck\n";
	//for (int i = 1; i <= n; i++) cout << i << ' ' << D[i] << '\n';
	ll mn = INF;
	for (int i = 2; i <= n; i++){
		ll W = INF / x;
		ll Z;
		if (W < dis[i][1]) Z = INF;
		else Z = x * dis[i][1] - pth[i][1];	
		mn = min(D[i] + Z, mn);
	}
	return (mn <= 0);
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m >> K;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= 2 * K; j++){
			if (j % 2 == 1) cin >> B[i][j / 2 + 1];
			else cin >> S[i][j / 2];
		}
	}
	for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) dis[i][j] = INF;
	for (int i =1 ; i <= m; i++){
		ll v, u, T;
		cin >> v >> u >> T;
		dis[v][u] = min(dis[v][u], T);
	} 
	for (int k = 1; k <= n; k++)for (int v = 1; v <= n; v++) for (int u = 1; u <= n; u++) dis[v][u] = min(dis[v][u], dis[v][k] + dis[k][u]);
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			if (dis[i][j] == INF) continue;
			for (int k = 1; k <= K; k++){
				if (S[j][k] == -1 || B[i][k] == -1) continue;
				pth[i][j] = max(pth[i][j], S[j][k] - B[i][k]);
			}
			//cout << i << ' ' << j << ' ' << pth[i][j] << '\n';
		}
	}
	ll l = 0, r = INF;
	while (r - l > 1){
		ll md = (l + r) >> 1;
		if (isval(md)) l = md;
		else r = md;
	}
	cout << l;
//	isval(5);






	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 375 ms 2304 KB Output is correct
2 Correct 347 ms 1528 KB Output is correct
3 Correct 356 ms 1504 KB Output is correct
4 Correct 51 ms 896 KB Output is correct
5 Correct 52 ms 1016 KB Output is correct
6 Correct 50 ms 896 KB Output is correct
7 Correct 51 ms 896 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 53 ms 896 KB Output is correct
10 Correct 51 ms 1020 KB Output is correct
11 Correct 52 ms 896 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 33 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 896 KB Output is correct
2 Correct 50 ms 896 KB Output is correct
3 Correct 52 ms 1024 KB Output is correct
4 Correct 47 ms 1024 KB Output is correct
5 Correct 57 ms 1024 KB Output is correct
6 Incorrect 4 ms 512 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 361 ms 1664 KB Output is correct
2 Correct 412 ms 2432 KB Output is correct
3 Correct 353 ms 1764 KB Output is correct
4 Correct 362 ms 1784 KB Output is correct
5 Correct 357 ms 1784 KB Output is correct
6 Correct 355 ms 1536 KB Output is correct
7 Correct 52 ms 1020 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 53 ms 1024 KB Output is correct
10 Correct 52 ms 1024 KB Output is correct
11 Correct 37 ms 896 KB Output is correct
12 Correct 50 ms 896 KB Output is correct
13 Incorrect 17 ms 896 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 896 KB Output is correct
2 Correct 50 ms 896 KB Output is correct
3 Correct 52 ms 1024 KB Output is correct
4 Correct 47 ms 1024 KB Output is correct
5 Correct 57 ms 1024 KB Output is correct
6 Incorrect 4 ms 512 KB Output isn't correct
7 Halted 0 ms 0 KB -