Submission #499571

#TimeUsernameProblemLanguageResultExecution timeMemory
499571fatemetmhrTravelling Merchant (APIO17_merchant)C++17
100 / 100
104 ms5100 KiB
// ~Be name khoda~ // #include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define fi first #define se second #define cl clear #define endll '\n' const int maxn = 110; const int maxk = 2e3 + 10; const int maxnt = 1.2e6 + 10; const int maxn3 = 1e3 + 10; const int mod = 1e9 + 7; const ll inf = 1e9 + 10; const ll inf2 = 2e18; ll dp[2][maxn][maxn]; ll dis[maxn][maxn], val[maxn][maxn]; ll s[maxn][maxk], b[maxn][maxk]; int n, m, k; inline bool check(ll avg){ for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){ if(i == j) dp[1][i][j] = 1; else dp[1][i][j] = dis[i][j] == inf ? inf2 : dis[i][j] * avg - val[i][j]; } for(int i = 0; i < n; i++) for(int a = 0; a < n; a++) for(int b = 0; b < n; b++){ if(i != a && i != b) dp[i%2][a][b] = min({inf2, dp[(i + 1)%2][a][b], dp[(i + 1)%2][a][i] + dp[(i + 1)%2][i][b]}); else dp[i%2][a][b] = dp[(i + 1)%2][a][b]; } ll mn = 1; for(int i = 0; i < n; i++) mn = min(mn, dp[(n - 1)%2][i][i]); return mn <= 0; } int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin >> n >> m >> k; for(int i = 0; i < n; i++){ for(int j = 0; j < k; j++) cin >> b[i][j] >> s[i][j]; } memset(dp, 60, sizeof dp); for(int i = 0; i < m; i++){ int a, b, len; cin >> a >> b >> len; a--; b--; dp[1][a][b] = len; } for(int i = 0; i < n; i++) dp[1][i][i] = 0; for(int i = 0; i < n; i++) for(int a = 0; a < n; a++) for(int b = 0; b < n; b++) dp[i%2][a][b] = min({inf, dp[(i + 1)%2][a][b], dp[(i + 1)%2][a][i] + dp[(i + 1)%2][i][b]}); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){ dis[i][j] = min(inf, dp[(n - 1)%2][i][j]); if(i != j) for(int r = 0; r < k; r++) if(min(s[j][r], b[i][r]) != -1) val[i][j] = max(val[i][j], s[j][r] - b[i][r]); } ll lo = 0, hi = inf; while(hi - lo > 1){ ll mid = (lo + hi) >> 1; if(check(mid)) lo = mid; else hi = mid; } cout << lo << 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...