답안 #114855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
114855 2019-06-03T15:18:59 Z maruii 여행하는 상인 (APIO17_merchant) C++14
0 / 100
99 ms 1404 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define ff first
#define ss second

int N, M, K;
int B[101][1000], S[101][1000], E[101][101], W[101][101];

bool f(ll m) {
	ll X[101][101] = {0};
	for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) X[i][j] = -W[i][j] + m * E[i][j];
	for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) for (int k = 1; k <= N; ++k) {
		if (j != k) X[j][k] = min(X[j][k], X[j][i] + X[i][k]);
	}
	for (int i = 1; i < N; ++i) for (int j = i + 1; j <= N; ++j) if (X[i][j] + X[j][i] <= 0) return 1;
	return 0;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> N >> M >> K;
	for (int i = 1; i <= N; ++i) for (int j = 0; j < K; ++j) cin >> B[i][j] >> S[i][j];
	for (int i = 0; i < M; ++i) {
		int a, b, c; cin >> a >> b >> c;
		E[a][b] = c;
	}
	
	for (int x = 1; x <= N; ++x) for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j)
		if (i != j && E[i][x] && E[x][j] && (!E[i][j] || E[i][j] > E[i][x] + E[x][j])) E[i][j] = E[i][x] + E[x][j];
	for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) for (int k = 0; k < K; ++k)
		if(S[j][k] > 0 && B[i][k] > 0) W[i][j] = max(W[i][j], S[j][k] - B[i][k]);

	ll l = 0, r = 1e12;
	while (l < r) {
		ll m = l + r + 1 >> 1;
		if (f(m)) l = m;
		else r = m - 1;
	}
	cout << r;
	return 0;
}

Compilation message

merchant.cpp: In function 'int main()':
merchant.cpp:37:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   ll m = l + r + 1 >> 1;
          ~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 81 ms 1404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 896 KB Output is correct
2 Correct 10 ms 896 KB Output is correct
3 Correct 10 ms 896 KB Output is correct
4 Correct 8 ms 768 KB Output is correct
5 Correct 11 ms 896 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Incorrect 10 ms 896 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 1392 KB Output is correct
2 Correct 99 ms 1360 KB Output is correct
3 Correct 58 ms 1280 KB Output is correct
4 Incorrect 59 ms 1280 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 896 KB Output is correct
2 Correct 10 ms 896 KB Output is correct
3 Correct 10 ms 896 KB Output is correct
4 Correct 8 ms 768 KB Output is correct
5 Correct 11 ms 896 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Incorrect 10 ms 896 KB Output isn't correct
8 Halted 0 ms 0 KB -