제출 #750270

#제출 시각아이디문제언어결과실행 시간메모리
750270PoPularPlusPlus여행하는 상인 (APIO17_merchant)C++17
100 / 100
98 ms3404 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pb(e) push_back(e) #define sv(a) sort(a.begin(),a.end()) #define sa(a,n) sort(a,a+n) #define mp(a,b) make_pair(a,b) #define vf first #define vs second #define ar array #define all(x) x.begin(),x.end() const int inf = 0x3f3f3f3f; const int mod = 1000000007; const double PI=3.14159265358979323846264338327950288419716939937510582097494459230; mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); bool remender(ll a , ll b){return a%b;} //freopen("problemname.in", "r", stdin); //freopen("problemname.out", "w", stdout); void solve(){ int n , m , k; cin >> n >> m >> k; int b[n][k],s[n][k]; for(int i = 0; i < n; i++){ for(int j = 0; j < k; j++)cin>>b[i][j] >> s[i][j]; } ll dis[n][n]; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++)dis[i][j] = 1e18; } for(int i = 0; i < m; i++){ int a , bb , c; cin >> a >> bb >> c; a--; bb--; dis[a][bb] = c; } for(int a = 0; a < n; a++){ for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ dis[i][j] = min(dis[i][j] , dis[i][a] + dis[a][j]); } } } ll profit[n][n]; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ profit[i][j] = 0; for(int a = 0; a < k; a++){ if(b[i][a] != -1 && s[j][a] != -1) profit[i][j] = max(profit[i][j] , (ll)-b[i][a] +s[j][a]); } } } ll l = 1 , r = 1e11 , ans = 0; ll new_dis[n][n]; while(l <= r){ ll mid = (l + r)/2; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ ll need = (1e16/mid); need++; new_dis[i][j] = profit[i][j] - min(need , dis[i][j])*mid; } } for(int a = 0; a < n; a++){ for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ new_dis[i][j] = max(new_dis[i][j] , new_dis[i][a] + new_dis[a][j]); } } } ll mx = -1e18; for(int i = 0; i < n; i++){ mx = max(mx , new_dis[i][i]); } if(mx >= 0){ ans = mid; l = mid + 1; } else r = mid - 1; } cout << ans << '\n'; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); //int t;cin >> t;while(t--) solve(); 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...