Submission #948291

#TimeUsernameProblemLanguageResultExecution timeMemory
948291quanlt206Job Scheduling (IOI19_job)C++17
24 / 100
102 ms21424 KiB
#include<bits/stdc++.h> #define X first #define Y second #define all(x) begin(x), end(x) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define FORD(i, b, a) for(int i = (b); i >= (a); i--) #define REP(i, a, b) for (int i = (a); i < (b); i++) #define mxx max_element #define mnn min_element #define SQR(x) (1LL * (x) * (x)) #define MASK(i) (1LL << (i)) #define Point Vector #define left Left #define right Right #define div Div using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ld; typedef pair<db, db> pdb; typedef pair<ld, ld> pld; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef pair<ll, ll> pll; typedef pair<ll, pll> plll; typedef pair<ll, int> pli; typedef pair<ll, pii> plii; template<class A, class B> bool maximize(A& x, B y) { if (x < y) return x = y, true; else return false; } template<class A, class B> bool minimize(A& x, B y) { if (x > y) return x = y, true; else return false; } /* END OF TEMPLATE */ const int N = 2e5 + 7; int p[N], u[N], d[N], n; bool checkSub1() { REP(i, 1, n) if (p[i] != i - 1) return false; return true; } namespace sub1 { ll Process() { ll res = 0, sum_t = 0; REP(i, 0, n) { sum_t+=d[i]; res+=1LL * u[i] * sum_t; } return res; } } bool checkSub3() { REP(i, 1, n) if (p[i] != 0) return false; return true; } namespace sub3 { ll Process() { vector<int> node; ll res = 0, sum_t = 0; sum_t+=d[0]; res+=sum_t * u[0]; REP(i, 1, n) if (u[i] > 0) node.push_back(i); sort(all(node), [=](int x, int y){ return (ld)d[x] / u[x] < (ld)d[y] / u[y]; }); for (auto x : node) { sum_t+=d[x]; res+=sum_t * u[x]; } return res; } } namespace sub4 { vector<int> v[N]; ll Process() { ll res = 0, sum_u = 0; REP(i, 0, n) sum_u+=u[i]; vector<int> node; REP(i, 1, n) v[p[i]].push_back(i); int cntLoop = 0; node.push_back(0); while (cntLoop < n) { cntLoop++; ll Min = 1e18; int idx = -1; sort(all(node), [=](int x, int y){ return (ld)d[x] / u[x] < (ld)d[y] / u[y]; }); REP(i, 0, 1) if (minimize(Min, 1LL * d[node[i]] * sum_u)) idx = i; res+=Min; sum_u-=u[node[idx]]; // cout<<node[idx]<<endl; vector<int> new_node; REP(i, 0, (int)node.size()) if (i == idx) { for (auto x : v[node[i]]) new_node.push_back(x); } else new_node.push_back(node[i]); node = new_node; } return res; } } int64_t scheduling_cost(vector<int> P, vector<int> U, vector<int> D) { n = P.size(); REP(i, 0, n) { p[i] = P[i]; u[i] = U[i]; d[i] = D[i]; } if (checkSub1()) { return sub1::Process(); } if (checkSub3()) { return sub3::Process(); } return sub4::Process(); }
#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...