답안 #100439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100439 2019-03-11T10:01:32 Z square1001 여행하는 상인 (APIO17_merchant) C++14
0 / 100
1000 ms 1272 KB
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1012345678;
int main() {
	int N, M, K;
	cin >> N >> M >> K;
	vector<vector<int> > B(N, vector<int>(K)), S(N, vector<int>(K));
	for(int i = 0; i < N; ++i) {
		for(int j = 0; j < K; ++j) {
			cin >> B[i][j] >> S[i][j];
		}
	}
	vector<vector<int> > D(N, vector<int>(N, inf));
	for(int i = 0; i < N; ++i) D[i][i] = 0;
	for(int i = 0; i < M; ++i) {
		int V, W, T;
		cin >> V >> W >> T; --V, --W;
		D[V][W] = T;
	}
	for(int i = 0; i < N; ++i) {
		for(int j = 0; j < N; ++j) {
			for(int k = 0; k < N; ++k) {
				D[j][k] = min(D[j][k], D[j][i] + D[i][k]);
			}
		}
	}
	long long L = 0, R = inf;
	for(int rep = 0; rep < 60; ++rep) {
		long long M = (L + R) / 2;
		vector<vector<long long> > C(N, vector<long long>(N, 1LL << 62));
		for(int i = 0; i < N; ++i) {
			C[i][i] = 0;
			for(int j = 0; j < N; ++j) {
				for(int k = 0; k < K; ++k) {
					if(S[j][k] != -1 && B[i][k] != -1) {
						C[i][j] = min(C[i][j], (long long)(D[i][j]) * M - (S[j][k] - B[i][k]));
					}
				}
			}
		}
		for(int i = 0; i < N; ++i) {
			for(int j = 0; j < N; ++j) {
				for(int k = 0; k < N; ++k) {
					C[j][k] = min(C[j][k], C[j][i] + C[i][k]);
				}
			}
		}
		bool ok = true;
		for(int i = 0; i < N; ++i) {
			if(C[i][i] < 0) ok = false;
		}
		if(ok) R = M;
		else L = M;
	}
	cout << int(L) << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 812 ms 1272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 237 ms 512 KB Output is correct
2 Execution timed out 1085 ms 1144 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -