# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
50121 | 2018-06-07T15:53:00 Z | mohammad_kilani | 여행하는 상인 (APIO17_merchant) | C++17 | 333 ms | 1900 KB |
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define oo 2000000000 const int N = 150 , K = 1100; long long dist[N][N] , best[N][N]; long double cur[N][N]; int b[N][K] , s[N][K]; int n , m , k , u , v , w; bool check(long long mid){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(i == j) continue; cur[i][j] = (long double)dist[i][j] * mid - best[i][j]; } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ for(int k=1;k<=n;k++){ if(i == j || i == k) continue; cur[j][k] = min(cur[j][k],cur[j][i] + cur[i][k]); } } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(i != j) if(cur[i][j] + (long double)mid * dist[j][i] <= 0.00001) return true; } } return false; } int main() { scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(i != j) dist[i][j] = 1e18; } } for(int i=1;i<=n;i++){ for(int j=1;j<=k;j++){ scanf("%d%d",&b[i][j],&s[i][j]); } } for(int i=0;i<m;i++){ scanf("%d%d%d",&u,&v,&w); dist[u][v] = min(dist[u][v],(long long)w); } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ for(int k=1;k<=n;k++){ dist[j][k] = min(dist[j][k],(long long) dist[j][i] + dist[i][k]); } } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(i == j) continue; best[i][j] = -1e18; if(dist[i][j] >= (long long)1e18) continue; best[i][j] = 0; for(int l=1;l<=k;l++){ if(b[i][l] != -1 && s[j][l] != -1) best[i][j] = max(best[i][j], (long long)s[j][l] - b[i][l]); } } } long long low = 1 , high = 1e11 , ans = 0 , mid = 0; while(high >= low){ mid = (low + high) / 2; if(check(mid)){ ans = mid; low = mid + 1; continue; } else high = mid - 1; } cout << ans << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 272 ms | 1656 KB | Output is correct |
2 | Correct | 277 ms | 1764 KB | Output is correct |
3 | Correct | 247 ms | 1800 KB | Output is correct |
4 | Correct | 33 ms | 1800 KB | Output is correct |
5 | Correct | 38 ms | 1800 KB | Output is correct |
6 | Correct | 32 ms | 1800 KB | Output is correct |
7 | Correct | 33 ms | 1800 KB | Output is correct |
8 | Correct | 2 ms | 1800 KB | Output is correct |
9 | Correct | 31 ms | 1800 KB | Output is correct |
10 | Correct | 35 ms | 1800 KB | Output is correct |
11 | Correct | 32 ms | 1800 KB | Output is correct |
12 | Correct | 3 ms | 1800 KB | Output is correct |
13 | Correct | 47 ms | 1800 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 36 ms | 1800 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 333 ms | 1900 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 36 ms | 1800 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |