제출 #978782

#제출 시각아이디문제언어결과실행 시간메모리
978782nnin여행하는 상인 (APIO17_merchant)C++17
0 / 100
999 ms2384 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long int N, M, K; ll B[105][1005], S[105][1005], mindis[105][105], profit[105][105], mat[105][105]; bool check(ll x) { for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) { if(mindis[i][j]==1e18 || i==j) mat[i][j] = -1e18; else mat[i][j] = profit[i][j]-(x*mindis[i][j]); } for(int k=1;k<=K;k++) for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) { if(mindis[i][k]==1e18 || mindis[k][j]==1e18) continue; mat[i][j] = max(mat[i][j], mat[i][k]+mat[k][j]); } for(int i=1;i<=N;i++) { if(mat[i][i]>=0) return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>N>>M>>K; for(int i=1;i<=N;i++) for(int j=1;j<=K;j++) cin>>B[i][j]>>S[i][j]; for(int i=1;i<=N;i++) { for(int j=1;j<=N;j++) mindis[i][j] = 1e18; mindis[i][i] = 0; } while(M--) { int u, v; ll w; cin>>u>>v>>w; mindis[u][v] = w; } for(int k=1;k<=N;k++) for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) { mindis[i][j] = min(mindis[i][j], mindis[i][k]+mindis[k][j]); } for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) { if(i==j || mindis[i][j]==1e18) continue; for(int k=1;k<=K;k++) { if(B[i][k]==-1 || S[j][k]==-1) continue; profit[i][j] = max(profit[i][j], S[j][k]-B[i][k]); } } ll l = 0, r = 1e18; while(l<r) { ll m = (l+r+1)/2; if(check(m)) l = m; else r = m-1; } cout<<l; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...