답안 #976908

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976908 2024-05-07T08:54:19 Z Halym2007 여행하는 상인 (APIO17_merchant) C++17
0 / 100
58 ms 2096 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair <ll, ll>
#define ff first
#define ss second
#define sz size()
// long long-a uns ber

const int N = 1e2 + 5;
ll baha[N], vis[N], buy[N][N], sell[N][N], n, m, d, dis[N][N], profit[N][N];
vector <ll> nodes;
vector <pii> v[N];
ll node, val, new_jog;

ll ugrat () {
	ll ret = 0;
	for (int i = 1; i < (int)nodes.sz; ++i) {
		for (int j = 0; j < i; ++j) {
			ll x = nodes[j], y = nodes[i];
			baha[i] = max (baha[i], baha[j] + profit[x][y]);
		}
		ret = max (ret, baha[i]);
	}
	for (int i = 0; i < (int)nodes.sz; ++i) {
		baha[i] = 0;
	}
	return ret;
 }

void dfs (ll x, ll wagt) {
	if (vis[x]) {
		if (x == node) {
			nodes.pb(x);
			ll jog = ugrat ();
			jog -= val * wagt;	
			if (jog >= 0) new_jog = 1;
			nodes.pop_back();
		}
		return;
	}
	vis[x] = 1;
	nodes.pb (x);
	for (pii i : v[x]) {
		dfs (i.ff, wagt + i.ss);
	}
	vis[x] = 0;
	nodes.pop_back();
}


bool check (ll x) {
	// jog - x * time >= 0
	for (ll i = 1; i <= n; ++i) {
		node = i;val = x;
		new_jog = 0;
		dfs (node, 0);
		if (new_jog) return 1;
	}
	return 0;
}



int main () {
//	freopen ("input.txt", "r", stdin);
	cin >> n >> m >> d;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= d; ++j) {
			cin >> buy[i][j] >> sell[i][j];
		}
	}
	for (int i = 1; i <= m; ++i) {
		ll l, r, w;
		cin >> l >> r >> w;
		v[l].pb ({r, w});
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (i == j) continue;
			for (int k = 1; k <= d; ++k) {
				// k-th item-y i-njiden satyn alyan j-nynjyda satyan
				if (sell[j][k] != -1 and buy[i][k] != -1) 
				profit[i][j] = max (profit[i][j], sell[j][k] - buy[i][k]);
			}
		}
	}
	ll l = 0, r = 1e9, jog = 0;
	while (l <= r) {
		ll md = (l + r) / 2;
		if (check (md)) {
			jog = md;
			l = md + 1;
		}
		else {
			r = md - 1;
		}
	}
	cout << jog;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 40 ms 1832 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Incorrect 5 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 604 KB Output is correct
2 Runtime error 58 ms 2096 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Incorrect 5 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -