Submission #231942

# Submission time Handle Problem Language Result Execution time Memory
231942 2020-05-15T11:43:01 Z Atalasion Travelling Merchant (APIO17_merchant) C++14
12 / 100
243 ms 2680 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();
	fill(D + 1, D + n + 1, INF);
	//cout << D[1] << ' ' << D[2] << '\n';
	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];
			if (i == 1) Z--;
			G[i].pb({j, Z});
//			cout << i << ' ' << j << ' ' << x * dis[i][j] - pth[i][j] << '\n';
		}
	}
	D[1] = 0;
	for (int i = 1; i <= n + 2; i++){
		bool f = 0;
		for (int j = 1; j <= n; j++){
			for (auto u:G[j]){
				relax(j, u.F, u.S);
			}
		}
	}
	return (D[1] < 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;
}

Compilation message

merchant.cpp: In function 'bool isval(ll)':
merchant.cpp:56:8: warning: unused variable 'f' [-Wunused-variable]
   bool f = 0;
        ^
# Verdict Execution time Memory Grader output
1 Correct 211 ms 2424 KB Output is correct
2 Correct 175 ms 1528 KB Output is correct
3 Correct 175 ms 1408 KB Output is correct
4 Correct 28 ms 896 KB Output is correct
5 Correct 28 ms 896 KB Output is correct
6 Correct 28 ms 896 KB Output is correct
7 Correct 29 ms 1016 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 27 ms 896 KB Output is correct
10 Correct 28 ms 896 KB Output is correct
11 Correct 34 ms 896 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 20 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1024 KB Output is correct
2 Incorrect 28 ms 896 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 189 ms 1664 KB Output is correct
2 Correct 243 ms 2680 KB Output is correct
3 Incorrect 179 ms 1536 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1024 KB Output is correct
2 Incorrect 28 ms 896 KB Output isn't correct
3 Halted 0 ms 0 KB -