Submission #265356

#TimeUsernameProblemLanguageResultExecution timeMemory
265356_7_7_Travelling Merchant (APIO17_merchant)C++17
0 / 100
398 ms3828 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define int long long //#pragma GCC optimize("Ofast") //#pragma comment(linker, "/stack:200000000") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4") #define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout); #define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define all(x) x.begin(), x.end() #define sz(s) (int)s.size() #define pb push_back #define ppb pop_back #define mp make_pair #define s second #define f first typedef pair < long long, long long > pll; typedef pair < int, int > pii; typedef unsigned long long ull; typedef vector < pii > vpii; typedef vector < int > vi; typedef long double ldb; typedef long long ll; typedef double db; typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set; const int inf = 1e9, maxn = 2e5 + 48, mod = 998244353, N = 112; const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300; const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9); const db eps = 1e-12, pi = acos(-1); const ll INF = 1e18; int n, m, k, b[N][N*N], s[N][N*N], d[N][N], c[N][N], v, u, w, C[N][N], D[N][N]; struct item { int v, to, c, d; bool operator < (const item &y) const { if (y.d == INF) return 1; if (d == INF) return 0; if (c * y.d == d * y.c) return mp(v, to) < mp(y.v, y.to); return c * y.d > d * y.c; } }; set < item > q; item tmp, tmp1; main () { scanf("%lld%lld%lld", &n, &m, &k); for (int i = 1; i <= n; ++i) for (int j = 1; j <= k; ++j) scanf("%lld%lld", &b[i][j], &s[i][j]); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if (i != j) d[i][j] = INF; while (m--) { scanf("%lld%lld%lld", &v, &u, &w); d[v][u] = min(d[v][u], w); } for (int k = 1; k <= n; ++k) for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if (d[i][k] < INF && d[k][j] < INF) d[i][j] = min(d[i][j], d[i][k] + d[k][j]); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) for (int x = 1; x <= k; ++x) if (b[i][x] != -1 && s[j][x] != -1) c[i][j] = max(c[i][j], s[j][x] - b[i][x]); int ans = 0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if (i != j) { C[i][j] = 0; D[i][j] = INF; } vector < item > V; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if (i != j && d[i][j] < INF) { tmp.v = i; tmp.to = j; tmp.c = c[i][j]; tmp.d = d[i][j]; V.pb(tmp); } sort(all(V)); for (auto x : V) { for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if (i != j) { tmp.c = C[i][x.v] + x.c + C[x.to][j]; tmp.d = D[i][x.v] + x.d + D[x.to][j]; if (tmp.d < INF) { tmp1.c = C[i][j]; tmp1.d = D[i][j]; if (tmp < tmp1) { D[i][j] = tmp.d; C[i][j] = tmp.c; } } } } for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if (i != j) ans = max(ans, (C[i][j] + c[j][i]) / (D[i][j] + d[j][i])); cout << ans << endl; }

Compilation message (stderr)

merchant.cpp:65:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main () {
      |       ^
merchant.cpp: In function 'int main()':
merchant.cpp:66:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   66 |  scanf("%lld%lld%lld", &n, &m, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:69:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   69 |    scanf("%lld%lld", &b[i][j], &s[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   78 |   scanf("%lld%lld%lld", &v, &u, &w);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...