제출 #891090

#제출 시각아이디문제언어결과실행 시간메모리
89109012345678여행하는 상인 (APIO17_merchant)C++17
100 / 100
76 ms4360 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=105, kx=1005; ll n, m, k, dp[nx][nx], p[nx][nx], b[nx][kx], s[nx][kx], ds[nx][nx], u, v, w, l=0, r=1e9; bool check(ll x) { for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) dp[i][j]=(ds[i][j]>1e9)?-1e18:p[i][j]-x*ds[i][j]; for (int i=1; i<=n; i++) dp[i][i]=-1e18; for (int m=1; m<=n; m++) for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) dp[i][j]=max(dp[i][j], dp[i][m]+dp[m][j]); for (int i=1; i<=n; i++) if (dp[i][i]>=0) return 1; return 0; } int main() { cin.tie(NULL)->sync_with_stdio(false); 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++) ds[i][j]=1e15; for (int i=1; i<=n; i++) ds[i][i]=0; for (int i=1; i<=m; i++) { cin>>u>>v>>w; ds[u][v]=w; } for (int m=1; m<=n; m++) for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) ds[i][j]=min(ds[i][j], ds[i][m]+ds[m][j]); for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) for (int g=1; g<=k; g++) if (s[j][g]!=-1&&b[i][g]!=-1&&i!=j) p[i][j]=max(p[i][j], s[j][g]-b[i][g]); while (l<r) { ll md=(l+r+1)/2; if (check(md)) l=md; else r=md-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...