제출 #374239

#제출 시각아이디문제언어결과실행 시간메모리
374239ivan_tudor여행하는 상인 (APIO17_merchant)C++14
0 / 100
92 ms2156 KiB
#include<bits/stdc++.h> using namespace std; const long long N = 105; long long mind[N][N]; long long maxp[N][N]; long long newc[N][N]; long long b[N][1005]; long long s[N][1005]; long long n; bool check(long long R){ for(long long i =1 ; i<=n;i++) for(long long j =1 ; j<=n;j++){ if(mind[i][j] == LLONG_MAX) newc[i][j] = LLONG_MAX; else newc[i][j] = maxp[i][j] - R * mind[i][j]; } for(long long k = 1; k <=n;k++){ for(long long i = 1; i<=n;i++) for(long long j =1 ; j<=n;j++){ if(newc[k][j] != LLONG_MAX && newc[i][k] != LLONG_MAX && newc[i][k] + newc[k][j] < newc[i][j]) newc[i][j] = newc[i][k] + newc[k][j]; } } for(long long i =1 ; i<=n;i++){ if(newc[i][i] >=0) return true; } return false; } int main() { //freopen(".in","r",stdin); ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); long long m, k; cin>>n>>m>>k; for(long long i=1;i<=n;i++){ for(long long j = 1; j<=k;j++) cin>>b[i][j]>>s[i][j]; } for(long long i = 1; i<=n;i++) for(long long j = 1; j<=n;j++) mind[i][j] = LLONG_MAX; for(long long i = 1; i<=n;i++) mind[i][i] = 0; for(long long i = 1; i<=m;i++){ long long x, y, d; cin>>x>>y>>d; mind[x][y] = d; } for(long long k = 1 ; k<=n;k++){ for(long long i =1 ; i<=n;i++) for(long long j =1 ; j<=n;j++){ if(mind[i][k] != LLONG_MAX && mind[k][j] != LLONG_MAX && mind[i][j] > mind[i][k] + mind[k][j]) mind[i][j] = mind[i][k] + mind[k][j]; } } for(long long i = 1; i<=n;i++){ for(long long j = 1; j<=n;j++){ maxp[i][j] = 0; for(long long l = 1; l<=k;l++){ if(b[i][l] == -1 || s[j][l] == -1) continue; maxp[i][j] = max(maxp[i][j], s[j][l] - b[i][l]); } } } long long pas = 0; for(long long p2 = 1LL<<30; p2 > 0; p2/=2){ if(check(pas + p2)) pas +=p2; } cout<<pas; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...