제출 #391041

#제출 시각아이디문제언어결과실행 시간메모리
391041amirmohammad_nezami여행하는 상인 (APIO17_merchant)C++14
100 / 100
110 ms4196 KiB
// In the name of God #include <bits/stdc++.h> using namespace std; #define F first #define S second #define PB push_back #define MP make_pair #define lc 2 * v #define rc 2 * v + 1 #define mid (s + e) / 2 #define _sz(e) (int)e.size() #define _all(e) e.begin() , e.end() #define ll long long #define int long long #define ld long double #define pii pair <int , int> #define pll pair <long long , long long> #define piii pair <int , pair <int , int> > #define FAST ios::sync_with_stdio(0);cin.tie(0) #define Unique(e) e.resize(unique(_all(e)) - e.begin()) #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") const int maxn = 100 + 5 , N = 10000 + 5 , SQ = 500 , base = 800287 , mod = 1e9 + 7 , INF = 1e18 + 5 , lg = 20; const ld eps = 1e-4; int n , m , k , mx[maxn][maxn]; int dist[maxn][maxn] , dp[maxn][maxn]; vector <pll> item[maxn] , edges[maxn]; inline bool calc(int x) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if(dist[i][j] == INF) { dp[i][j] = -INF; } else { dp[i][j] = mx[i][j] - x * dist[i][j]; } } } for (int t = 0; t < n; ++t) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { dp[i][j] = max(dp[i][j] , dp[i][t] + dp[t][j]); } } } for (int i = 0; i < n; ++i) { if(dp[i][i] >= 0) { return 1; } } return 0; } int32_t main() { FAST; cin >> n >> m >> k; for (int i = 0; i < n; ++i) { for (int j = 0; j < k; ++j) { int x , y; cin >> x >> y; item[i].PB({x , y}); } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { for (int t = 0; t < k; ++t) { if(item[j][t].S == -1 || item[i][t].F == -1) { continue; } int val = item[j][t].S - item[i][t].F; mx[i][j] = max(mx[i][j] , val); } } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { dist[i][j] = INF; } } for (int i = 0; i < m; ++i) { int x , y , z; cin >> x >> y >> z; x-- , y--; dist[x][y] = z; } for (int t = 0; t < n; ++t) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { dist[i][j] = min(dist[i][j] , dist[i][t] + dist[t][j]); } } } int s = 0 , e = 1e9 + 1; while(s < e - 1) { if(calc(mid)) { s = mid; } else { e = mid; } } cout << s << '\n'; } // Mistakes: // * Read the problem carefully. // * Check maxn. // * Overflows.
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...