Submission #639063

#TimeUsernameProblemLanguageResultExecution timeMemory
639063shmadTravelling Merchant (APIO17_merchant)C++17
12 / 100
42 ms50028 KiB
#pragma GCC optimize("O3", "unroll-loops") // "Ofast" #pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt") #include <bits/stdc++.h> //#define int long long #define vt vector #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define ff first #define ss second #define dbg(x) cerr << #x << " = " << x << '\n' #define bit(x, i) ((x) >> (i) & 1) using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vvt = vt< vt<int> >; const int N = 1e6 + 5, mod = 1e9 + 7, B = 500; const ll inf = 1e18 + 7, LIM = (1ll << 60); const double eps = 1e-6; int n, m, k; ll b[105][1005], s[105][1005]; vt<pii> g[N], g1[N]; void calc (vt<ll> &d, bool c) { set<pair<ll, int>> st; d[1] = 0; st.insert({0, 1}); while (!st.empty()) { pii nw = *st.begin(); st.erase(st.begin()); int v = nw.ss; for (auto [to, w]: (c ? g[v] : g1[v])) { if (d[to] > d[v] + w) { d[to] = d[v] + w; st.insert({d[to], to}); } } } } void solve () { cin >> n >> m >> k; for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) cin >> b[i][j] >> s[i][j]; } for (int i = 1; i <= m; i++) { int x, y, w; cin >> x >> y >> w; g[x].pb({y, w}); g1[y].pb({x, w}); } vt<ll> d(n + 1, inf), d1(n + 1, inf); calc(d, 0); calc(d1, 1); for (int i = 1; i <= n; i++) d[i] += d1[i]; ll ans = 0; for (int i = 2; i <= n; i++) { for (int j = 1; j <= k; j++) { if ((s[i][j] - b[1][j]) > 0) ans = max(ans, (s[i][j] - b[1][j]) / d[i]); } } cout << ans; cout << '\n'; } bool testcases = 0; signed main() { #ifdef ONLINE_JUDGE freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif cin.tie(0) -> sync_with_stdio(0); int test = 1; if (testcases) cin >> test; for (int cs = 1; cs <= test; cs++) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...