Submission #265267

#TimeUsernameProblemLanguageResultExecution timeMemory
265267abacaba여행하는 상인 (APIO17_merchant)C++14
12 / 100
441 ms2296 KiB
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
 
// typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <typename T> inline T range(T l, T r) {
    return uniform_int_distribution<T>(l, r)(rng);
}
 
template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}
 
#define int long long

const int mod = 1e9 + 7;
const int inf = 2e15;
const int N = 1e2 + 15;
const int K = 1e3 + 15;
int n, m, k, buy[N][K], sell[N][K];
int g[N][N];

int mx[N][N], d[N][N];
int dp[N][N];

bool used[N];

bool check(int mid) {
	for(int i = 0; i < N; ++i) {
		fill(d[i], d[i] + N, inf);
		fill(dp[i], dp[i] + N, inf);
	}

	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			if(g[i][j])
				d[i][j] = g[i][j] * mid;

	for(int k = 1; k <= n; ++k)
		for(int i = 1; i <= n; ++i)
			for(int j = 1; j <= n; ++j)
				Min(d[i][j], d[i][k] + d[k][j]);
	
	memcpy(mx, d, sizeof(d));

	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			for(int s = 1; s <= k; ++s)
				if(buy[i][s] != -1 && sell[j][s] != -1)
					Min(mx[i][j], d[i][j] + buy[i][s] - sell[j][s]);
	
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			if(i != j)
				Min(dp[i][j], mx[i][j]);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			for(int l = 1; l <= n; ++l)
				Min(dp[i][l], dp[i][j] + mx[j][l]);
	int ans = inf;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			if(i != j)
				Min(ans, dp[i][j] + mx[j][i]);
	return ans <= 0;
}

main() {
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
//	freopen("input.txt", "r", stdin);
	cin >> n >> m >> k;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= k; ++j)
			cin >> buy[i][j] >> sell[i][j];
	for(int i = 1; i <= m; ++i) {
		int u, v;
		cin >> u >> v;
		cin >> g[u][v];
	}
	int l = 1, r = 2e9, res = 0;
	while(l <= r) {
		int mid = l + r >> 1;
		if(check(mid))
			l = mid + 1, res = mid;
		else
			r = mid - 1;
	}
	cout << res << endl;
	return 0;
}

Compilation message (stderr)

merchant.cpp:113:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  113 | main() {
      |      ^
merchant.cpp: In function 'int main()':
merchant.cpp:127:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  127 |   int mid = l + r >> 1;
      |             ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...