제출 #792359

#제출 시각아이디문제언어결과실행 시간메모리
792359Alish여행하는 상인 (APIO17_merchant)C++17
21 / 100
91 ms904 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define F first #define S second #define pb push_back #define endl '\n' #define Mp make_pair #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " = " << x << endl #define set_dec(x) cout << fixed << setprecision(x); #define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define file_io freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout); #define int ll const int N = 123; const ll INF=INT_MAX; const int M=1e9+23; ll dist[N][N]; ll prof[N][N]; ll b[N][N], s[N][N]; ll temp[N][N]; int n , m, x ; bool check(int k){ for (int i=1; i<=n; i++) { for (int j=1; j<=n; j++){ temp[i][j]= k*min( dist[i][j] , INF/k)- prof[i][j]; } } for (int k=1; k<=n; k++){ for(int i=1; i<=n; i++){ for (int j=1; j<=n; j++){ temp[i][j]= min(temp[i][j], temp[i][k]+ temp[k][j]); } } } for (int i=1; i<=n; i++) if(temp[i][i]<=0) return 1; return 0; } int32_t main() { cin>>n>>m>>x; for (int i=1; i<=n; i++){ for (int j=1; j<=n; j++) dist[i][j]=INT_MAX; for (int j=1; j<=x; j++) cin>>b[i][j]>>s[i][j]; } for (int i=0; i<m; i++){ ll v, u, w; cin>>v>>u>>w; dist[v][u]=w; } for (int i=1; i<=n; i++){ for (int j=1; j<=n; j++){ for (int kk=1; kk<=x; kk++){ if(b[i][kk]!=-1 && s[j][kk]!=-1)prof[i][j]=max(prof[i][j], s[j][kk]-b[i][kk]); } } } for (int k=1; k<=n; k++){ for (int i=1; i<=n; i++){ for (int j=1; j<=n; j++){ dist[i][j]=min(dist[i][j], dist[i][k]+ dist[k][j]); } } } int l=0, r= 1e9+1; while(r-l>1) { int mid=(r+l)>>1; if(check(mid)) l=mid; else r=mid; } cout<<l<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...