# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
57352 | 2018-07-14T15:39:59 Z | gabrielsimoes | 여행하는 상인 (APIO17_merchant) | C++17 | 157 ms | 2196 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; const int MAXN = 101, MAXM = 9901, MAXK = 1001; const ll INF = 1e14; // const ll INF = 1000; int N, M, K; vector<pii> g[MAXN]; ll buy[MAXN][MAXK]; ll sell[MAXN][MAXK]; ll d[MAXN][MAXN]; ll gain[MAXN][MAXN]; ll dist[MAXN][MAXN]; bool ok[MAXN]; bool testPosCycle(ll x) { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { dist[i][j] = gain[i][j] - x * d[i][j]; } } for (int k = 1; k <= N; k++) { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { dist[i][j] = max(dist[i][j], dist[i][k] + dist[k][j]); } } } for (int i = 2; i <= N; i++) { if (dist[1][i] + dist[i][1] >= 0) { return true; } } return (dist[1][1] > 0); } int main() { scanf("%d%d%d", &N, &M, &K); for (int i = 1; i <= N; i++) { for (int k = 1; k <= K; k++) { scanf("%lld%lld", &buy[i][k], &sell[i][k]); } } for (int i = 1; i <= N; i++) { for (int k = 1; k <= N; k++) { d[i][k] = INF; } d[i][i] = 0; } for (int i = 1,a,b,c; i <= M; i++) { scanf("%d%d%d", &a, &b, &c); g[a].push_back({b, c}); d[a][b] = c; } for (int k = 1; k <= N; k++) { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { for (int k = 1; k <= K; k++) { if (buy[i][k] != -1 && sell[j][k] != -1) { gain[i][j] = max(gain[i][j], -buy[i][k] + sell[j][k]); } } } } ll l = 0, r = INF; while (l < r) { ll m = (l + r + 1LL) >> 1; if (testPosCycle(m)) l = m; else r = m-1; } printf("%lld\n", l); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 110 ms | 2040 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 14 ms | 2040 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 86 ms | 2040 KB | Output is correct |
2 | Correct | 157 ms | 2196 KB | Output is correct |
3 | Incorrect | 77 ms | 2196 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 14 ms | 2040 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |