Submission #265317

#TimeUsernameProblemLanguageResultExecution timeMemory
265317_7_7_Travelling Merchant (APIO17_merchant)C++14
12 / 100
142 ms2552 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; vector < pair < int, pii > > g[N]; vi order; struct item { int to, c, d; bool operator < (const item &y) const { if (c * y.d == d * y.c) return to < 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) { tmp.to = j; tmp.c = c[i][j]; tmp.d = d[i][j]; q.insert(tmp); } while (sz(q)) { tmp = *q.begin(); q.erase(q.begin()); ans = max(ans, (tmp.c + c[tmp.to][i]) / (tmp.d + d[tmp.to][i])); vector < item > del; vector < item > add; for (auto x : q) { tmp1 = x; tmp1.c = tmp.c + c[tmp.to][tmp1.to]; tmp1.d = tmp.d + d[tmp.to][tmp1.to]; if (tmp1 < x) { del.pb(x); add.pb(tmp1); } } for (auto x : del) q.erase(x); for (auto x : add) q.insert(x); } } cout << ans << endl; }

Compilation message (stderr)

merchant.cpp:62:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   62 | main () {
      |       ^
merchant.cpp: In function 'int main()':
merchant.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |  scanf("%lld%lld%lld", &n, &m, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:66:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   66 |    scanf("%lld%lld", &b[i][j], &s[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:75:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   75 |   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...