Submission #974000

#TimeUsernameProblemLanguageResultExecution timeMemory
974000Amirreza_FakhriTravelling Merchant (APIO17_merchant)C++17
100 / 100
71 ms4336 KiB
// In the name of the God #include <bits/stdc++.h> #define ll long long #define int long long #define pb push_back #define F first #define S second #define mp make_pair #define pii pair <int, int> #define smin(x, y) (x) = min((x), (y)) #define smax(x, y) (x) = max((x), (y)) #define all(x) (x).begin(), (x).end() using namespace std; // #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("avx2") const int inf = (1e9+7)*(1e9+7); const int mod = 998244353; const int maxn = 1e2+5, maxk = 1e3+5; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, m, k, d1[maxn][maxn], d2[maxn][maxn], b[maxn][maxk], s[maxn][maxk], p[maxn][maxn]; void fw(int d[maxn][maxn]) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int l = 0; l < n; l++) smin(d[j][l], d[j][i]+d[i][l]); } int32_t main() { ios_base::sync_with_stdio(0); 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]; for (int j = 0; j < n; j++) d1[i][j] = inf; } for (int i = 0; i < m; i++) { int v, u, w; cin >> v >> u >> w; d1[--v][--u] = w; } fw(d1); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int l = 0; l < k; l++) if (b[i][l] != -1 and s[j][l] != -1) smax(p[i][j], s[j][l]-b[i][l]); int l = 0, r = 1e9+10; while (r-l > 1) { int mid = (l+r)/2; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) d2[i][j] = mid*min(d1[i][j], inf/mid)-p[i][j]; fw(d2); bool nc = 0; for (int i = 0; i < n; i++) if (d2[i][i] <= 0) nc = 1; if (nc) l = mid; else r = mid; } cout << l << '\n'; return 0; } /* srand(time(0)); cout << (rand()%1900) + 1 << ' ' << (rand()%2)+5 << '\n'; */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...