| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1282388 | swishy123 | 여행하는 상인 (APIO17_merchant) | C++20 | 856 ms | 2316 KiB |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int def = 1e6+1;
const int maxk = 18;
const ll inf = 1e18;
const ld eps = 1e-9;
void solve(){
int n, m, k;
cin >> n >> m >> k;
vector<vector<ll>> b(n, vector<ll>(k, 0));
auto s = b;
for (int i = 0; i < n; i++){
for (int j = 0; j < k; j++)
cin >> b[i][j] >> s[i][j];
}
vector<vector<ll>> dp1(n, vector<ll>(n, inf));
for (int i = 0; i < m; i++){
ll u, v, w;
cin >> u >> v >> w;
u--; v--;
dp1[u][v] = min(dp1[u][v], w);
}
for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++)
dp1[i][j] = min(dp1[i][j], dp1[i][k] + dp1[k][j]);
ll l = 0, r = 1e9, mid = (l + r + 1) / 2;
while (l < r){
vector<vector<ll>> dp2(n, vector<ll>(n, inf));
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int u = 0; u < k; u++){
if (dp1[i][j] == inf || i == j)
continue;
dp2[i][j] = min(dp2[i][j], dp1[i][j] * mid);
if (b[i][u] == -1 || s[j][u] == -1)
continue;
dp2[i][j] = min(dp2[i][j], dp1[i][j] * mid - (s[j][u] - b[i][u]));
}
for (int o = 0; o < 2; o++){
for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++)
dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]);
}
bool ok = 0;
for (int i = 0; i < n; i++){
if (dp2[i][i] <= 0)
ok = 1;
}
if (ok)
l = mid;
else
r = mid - 1;
mid = (l + r + 1) / 2;
}
cout << l;
}
/*
w / dis >= mid
mid * dis - w <= 0
100 / 2 >= 1
200 / 4 >= 1
*/
main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (ifstream("input.txt").good()){
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int t = 1;
while (t--){
solve();
cout << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
