제출 #229170

#제출 시각아이디문제언어결과실행 시간메모리
229170laoriu여행하는 상인 (APIO17_merchant)C++14
0 / 100
101 ms3064 KiB
#include <bits/stdc++.h> using namespace std; const double ll=1e-9; typedef pair <int,int> pp; int n,m,k,S[102][1002],B[102][1002]; int c[102][102],d[102][102]; double cost[102][102],s[102]; vector <pp> A[102]; void prepare() { for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) { c[i][j]=0; for (int x=1;x<=k;x++) if (B[i][x]!=-1&&S[j][x]!=-1) c[i][j]=max(c[i][j],S[j][x]-B[i][x]); } for (int x=1;x<=n;x++) for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) d[i][j]=min(d[i][j],d[i][x]+d[x][j]); //for (int i=1;i<=n;i++) // for (int j=1;j<=n;j++) // cout<<i<<' '<<j<<' '<<d[i][j]<<' '<<c[i][j]<<endl; } int check(int x) { for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (i!=j) cost[i][j]=(double) x*d[i][j]-c[i][j]-ll; /* cout<<"cac "<<x<<endl; for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) cout<<i<<' '<<j<<' '<<cost[i][j]<<endl;*/ for (int i=1;i<=n;i++) s[i]=cost[1][i]; for (int x=1;x<=n;x++) for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (s[j]>s[i]+cost[i][j]) s[j]=s[i]+cost[i][j]; for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (s[j]>s[i]+cost[i][j]) return 1; return 0; } void solve() { //cout<<fixed<<setprecision(10)<<ll<<endl; 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++) if (i!=j) d[i][j]=1e9; for (int i=1;i<=m;i++) { int a,b,c;cin>>a>>b>>c; A[a].push_back({b,c}); d[a][b]=min(d[a][b],c); } prepare(); int d=0;int c=1e9; int res=0; while (d<=c) { int mid=(d+c)/2; if (check(mid)) {res=mid;d=mid+1;} else c=mid-1; } cout<<res; } int main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); //freopen("merchant.inp","r",stdin); //freopen("merchant.out","w",stdout); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...