Submission #145732

#TimeUsernameProblemLanguageResultExecution timeMemory
145732qkxwsmJob Scheduling (IOI19_job)C++14
0 / 100
3015 ms262148 KiB
#include "job.h" #include <bits/stdc++.h> using namespace std; template<class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template<class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } #define MP make_pair #define PB push_back #define LB lower_bound #define UB upper_bound #define fi first #define se second #define FOR(i, a, b) for (auto i = (a); i < (b); i++) #define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--) #define SZ(x) ((int) ((x).size())) #define ALL(x) (x).begin(), (x).end() #define MAXN 1000013 typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; int N; int parent[MAXN]; pll arr[MAXN]; vi edge[MAXN]; vi ord[MAXN]; ll ans = 0; vi comb(vi a, vi b) { vi res; int iter = 0; pii rec = {0, 0}; FOR(i, 0, SZ(a)) { while(iter < SZ(b) && (rec.fi + arr[b[iter]].fi) * arr[a[i]].se < (rec.se + arr[b[iter]].se) * arr[a[i]].fi) { res.PB(b[iter]); rec.fi += arr[b[iter]].fi; rec.se += arr[b[iter]].se; iter++; } rec = {0, 0}; res.PB(a[i]); } while(iter < SZ(b)) { res.PB(b[iter]); iter++; } return res; } void solve(int u) { for (int v : edge[u]) { solve(v); ord[u] = comb(ord[u], ord[v]); } ord[u].PB(u); } ll scheduling_cost(vi p, vi u, vi d) { N = SZ(p); // cerr << "HI\n"; FOR(i, 0, N) { parent[i] = p[i]; if (i == 0) { parent[i] = N; } else { edge[parent[i]].PB(i); } arr[i] = {u[i], d[i]}; // cerr << "parent " << parent[i] << endl; } solve(0); reverse(ALL(ord[0])); ll t = 0; // cerr << "ORD\n"; for (int u : ord[0]) { // cerr << u << endl; t += arr[u].se; ans += t * arr[u].fi; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...