Submission #230037

# Submission time Handle Problem Language Result Execution time Memory
230037 2020-05-07T20:35:05 Z MetB Travelling Merchant (APIO17_merchant) C++14
33 / 100
383 ms 4344 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
 
#define N 1000003
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
const ll INF = 1e17, MOD = INF + 7, MOD2 = 1e6 + 3;

ll un_dist[100][100], deal[100][100];
ll sell[100][1000], buy[100][1000], n, m, k;
ld d[100][100];

bool check (int x) {
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			if (un_dist[i][j] == INF) d[i][j] = -INF;
			else d[i][j] = (ld) deal[i][j] - (ld) x * un_dist[i][j];
		}


	for (int k = 0; k < n; k++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				if (d[i][j] < d[i][k] + d[k][j]) d[i][j] = d[i][k] + d[k][j];

	for (int i = 0; i < n; i++)
		if (d[i][i] >= 0) return true;

	return false;
}
 
int main () {
	cin >> n >> m >> k;

	for (int i = 0; i < n; i++)
		for (int j = 0; j < k; j++) {
			int b, s;
			cin >> buy[i][j] >> sell[i][j];
		}

	for (int i = 0; i < n; i++)
		fill (un_dist[i], un_dist[i] + n, (ll) INF);

	for (int i = 0; i < m; i++) {
		int u, v, l;
		cin >> u >> v >> l;
		u--, v--;
		un_dist[u][v] = min ((ll) l, un_dist[u][v]);
	}

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


	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int it = 0; it < k; it++)
				if (sell[j][it] > 0 && buy[i][it] > 0)
					deal[i][j] = max (deal[i][j], sell[j][it] - buy[i][it]);

	int l = 1, r = 1e9;

	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (check (mid)) l = mid;
		else r = mid - 1;
	}

	cout << l << endl;
}

Compilation message

merchant.cpp: In function 'int main()':
merchant.cpp:44:8: warning: unused variable 'b' [-Wunused-variable]
    int b, s;
        ^
merchant.cpp:44:11: warning: unused variable 's' [-Wunused-variable]
    int b, s;
           ^
# Verdict Execution time Memory Grader output
1 Correct 237 ms 2168 KB Output is correct
2 Incorrect 141 ms 1408 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 896 KB Output is correct
2 Correct 24 ms 896 KB Output is correct
3 Correct 25 ms 896 KB Output is correct
4 Correct 23 ms 896 KB Output is correct
5 Correct 35 ms 1024 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 24 ms 896 KB Output is correct
8 Correct 25 ms 896 KB Output is correct
9 Correct 24 ms 896 KB Output is correct
10 Correct 25 ms 896 KB Output is correct
11 Correct 30 ms 896 KB Output is correct
12 Correct 29 ms 896 KB Output is correct
13 Correct 25 ms 896 KB Output is correct
14 Correct 27 ms 896 KB Output is correct
15 Correct 31 ms 896 KB Output is correct
16 Correct 23 ms 896 KB Output is correct
17 Correct 37 ms 896 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 39 ms 1016 KB Output is correct
20 Correct 32 ms 896 KB Output is correct
21 Correct 30 ms 896 KB Output is correct
22 Correct 25 ms 896 KB Output is correct
23 Correct 26 ms 896 KB Output is correct
24 Incorrect 23 ms 896 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 256 ms 1624 KB Output is correct
2 Correct 383 ms 2296 KB Output is correct
3 Correct 217 ms 1536 KB Output is correct
4 Correct 263 ms 1912 KB Output is correct
5 Correct 259 ms 1912 KB Output is correct
6 Correct 175 ms 1608 KB Output is correct
7 Correct 37 ms 896 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 39 ms 1016 KB Output is correct
10 Correct 32 ms 896 KB Output is correct
11 Correct 30 ms 896 KB Output is correct
12 Correct 25 ms 896 KB Output is correct
13 Correct 26 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 896 KB Output is correct
2 Correct 24 ms 896 KB Output is correct
3 Correct 25 ms 896 KB Output is correct
4 Correct 23 ms 896 KB Output is correct
5 Correct 35 ms 1024 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 24 ms 896 KB Output is correct
8 Correct 25 ms 896 KB Output is correct
9 Correct 24 ms 896 KB Output is correct
10 Correct 25 ms 896 KB Output is correct
11 Correct 30 ms 896 KB Output is correct
12 Correct 29 ms 896 KB Output is correct
13 Correct 25 ms 896 KB Output is correct
14 Correct 27 ms 896 KB Output is correct
15 Correct 31 ms 896 KB Output is correct
16 Correct 23 ms 896 KB Output is correct
17 Correct 256 ms 1624 KB Output is correct
18 Correct 383 ms 2296 KB Output is correct
19 Correct 217 ms 1536 KB Output is correct
20 Correct 263 ms 1912 KB Output is correct
21 Correct 259 ms 1912 KB Output is correct
22 Correct 175 ms 1608 KB Output is correct
23 Correct 37 ms 896 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 39 ms 1016 KB Output is correct
26 Correct 32 ms 896 KB Output is correct
27 Correct 30 ms 896 KB Output is correct
28 Correct 25 ms 896 KB Output is correct
29 Correct 26 ms 896 KB Output is correct
30 Correct 157 ms 1536 KB Output is correct
31 Correct 167 ms 1788 KB Output is correct
32 Correct 206 ms 2680 KB Output is correct
33 Correct 163 ms 1664 KB Output is correct
34 Correct 162 ms 1664 KB Output is correct
35 Correct 158 ms 1672 KB Output is correct
36 Correct 359 ms 4216 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 151 ms 1408 KB Output is correct
40 Correct 157 ms 1536 KB Output is correct
41 Correct 158 ms 1536 KB Output is correct
42 Correct 149 ms 1408 KB Output is correct
43 Correct 148 ms 1408 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 32 ms 1024 KB Output is correct
46 Correct 33 ms 1024 KB Output is correct
47 Correct 31 ms 1144 KB Output is correct
48 Correct 340 ms 4344 KB Output is correct
49 Correct 334 ms 4216 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 237 ms 2168 KB Output is correct
52 Incorrect 141 ms 1408 KB Output isn't correct
53 Halted 0 ms 0 KB -