# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
52353 | 2018-06-25T14:08:46 Z | imeimi2000 | 여행하는 상인 (APIO17_merchant) | C++17 | 106 ms | 5412 KB |
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <unordered_map> #include <functional> #include <cstring> #include <cmath> #include <ctime> #include <cstdlib> using namespace std; typedef long long llong; typedef long double ld; typedef pair<int, int> pii; typedef pair<llong, llong> pll; int n, k; const int inf = 1e9 + 7; const llong linf = inf * inf; int buy[101][1001], sell[101][1001]; int t[101][101]; int c[101][101]; llong d[101][101]; int main() { int m; scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= k; ++j) { scanf("%d%d", buy[i] + j, sell[i] + j); } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { t[i][j] = inf; } } for (int i = 0; i < m; ++i) { int v, w, p; scanf("%d%d%d", &v, &w, &p); t[v][w] = p; } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { for (int p = 1; p <= n; ++p) { t[i][j] = min(t[i][j], t[i][p] + t[p][j]); } } } for (int i = 1; i <= k; ++i) { for (int j = 1; j <= n; ++j) { for (int p = 1; p <= n; ++p) { if (buy[j][i] != -1 && sell[p][i] != -1) { c[j][p] = max(c[j][p], sell[p][i] - buy[j][i]); } } } } int s = 0, e = inf; while (s < e) { m = (s + e + 1) / 2; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { d[i][j] = (llong)m * t[i][j] - c[i][j]; } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { for (int p = 1; p <= n; ++p) { d[i][j] = min(d[i][j], d[i][p] + d[p][j]); } } } int ch = 0; for (int i = 1; i <= n; ++i) { if (d[i][i] <= 0) { ch = 1; break; } } if (ch) s = m; else e = m - 1; } printf("%d\n", s); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 106 ms | 2552 KB | Output is correct |
2 | Correct | 38 ms | 2664 KB | Output is correct |
3 | Correct | 39 ms | 2664 KB | Output is correct |
4 | Incorrect | 7 ms | 2664 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 2664 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 2964 KB | Output is correct |
2 | Correct | 88 ms | 4676 KB | Output is correct |
3 | Correct | 42 ms | 4716 KB | Output is correct |
4 | Correct | 44 ms | 5192 KB | Output is correct |
5 | Correct | 44 ms | 5320 KB | Output is correct |
6 | Correct | 42 ms | 5412 KB | Output is correct |
7 | Correct | 8 ms | 5412 KB | Output is correct |
8 | Correct | 2 ms | 5412 KB | Output is correct |
9 | Correct | 8 ms | 5412 KB | Output is correct |
10 | Correct | 8 ms | 5412 KB | Output is correct |
11 | Correct | 11 ms | 5412 KB | Output is correct |
12 | Correct | 10 ms | 5412 KB | Output is correct |
13 | Correct | 8 ms | 5412 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 2664 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |