#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;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
/*
refs:
some solutions
*/
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "job.h"
struct S{
ll asum,bsum,val;
S(){
asum = bsum = val = 0;
}
S(ll x, ll y){
asum = x, bsum = y, val = x*y;
}
bool operator<(const S &other) const{
return bsum*other.asum < other.bsum*asum;
}
bool operator>(const S &other) const{
return bsum*other.asum > other.bsum*asum;
}
void merge(const S& other){
val += other.val+bsum*other.asum;
asum += other.asum;
bsum += other.bsum;
}
};
vector<ll> adj[N];
vector<ll> a,b;
priority_queue<S,vector<S>,greater<S>> pq[N];
void dfs1(ll u){
trav(v,adj[u]){
dfs1(v);
while(!pq[v].empty()){
pq[u].push(pq[v].top());
pq[v].pop();
}
}
S curr_group(a[u],b[u]);
while(!pq[u].empty()){
auto nxt_group = pq[u].top();
if(curr_group < nxt_group) break;
pq[u].pop();
curr_group.merge(nxt_group);
}
pq[u].push(curr_group);
}
long long scheduling_cost(std::vector<int> p, std::vector<int> a_, std::vector<int> b_) {
ll n = sz(p);
rep1(i,n-1){
adj[p[i]].pb(i);
}
a = vector<ll>(all(a_));
b = vector<ll>(all(b_));
dfs1(0);
S curr_group(0,0);
while(!pq[0].empty()){
curr_group.merge(pq[0].top());
pq[0].pop();
}
ll ans = curr_group.val;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
11352 KB |
Output is correct |
2 |
Correct |
3 ms |
11352 KB |
Output is correct |
3 |
Correct |
4 ms |
11356 KB |
Output is correct |
4 |
Correct |
4 ms |
11608 KB |
Output is correct |
5 |
Correct |
54 ms |
47368 KB |
Output is correct |
6 |
Correct |
92 ms |
73292 KB |
Output is correct |
7 |
Correct |
129 ms |
98860 KB |
Output is correct |
8 |
Correct |
154 ms |
118188 KB |
Output is correct |
9 |
Correct |
187 ms |
130332 KB |
Output is correct |
10 |
Correct |
158 ms |
121940 KB |
Output is correct |
11 |
Correct |
4 ms |
11356 KB |
Output is correct |
12 |
Correct |
188 ms |
134804 KB |
Output is correct |
13 |
Correct |
85 ms |
64416 KB |
Output is correct |
14 |
Runtime error |
439 ms |
262144 KB |
Execution killed with signal 9 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
11356 KB |
Output is correct |
2 |
Correct |
3 ms |
11356 KB |
Output is correct |
3 |
Correct |
3 ms |
11356 KB |
Output is correct |
4 |
Correct |
99 ms |
33516 KB |
Output is correct |
5 |
Correct |
95 ms |
33508 KB |
Output is correct |
6 |
Correct |
96 ms |
33468 KB |
Output is correct |
7 |
Correct |
93 ms |
33452 KB |
Output is correct |
8 |
Correct |
94 ms |
33508 KB |
Output is correct |
9 |
Correct |
104 ms |
33300 KB |
Output is correct |
10 |
Correct |
93 ms |
33404 KB |
Output is correct |
11 |
Correct |
95 ms |
33508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
11352 KB |
Output is correct |
2 |
Correct |
4 ms |
11476 KB |
Output is correct |
3 |
Correct |
3 ms |
11356 KB |
Output is correct |
4 |
Correct |
3 ms |
11356 KB |
Output is correct |
5 |
Correct |
7 ms |
12632 KB |
Output is correct |
6 |
Correct |
99 ms |
33980 KB |
Output is correct |
7 |
Correct |
97 ms |
33904 KB |
Output is correct |
8 |
Correct |
102 ms |
33980 KB |
Output is correct |
9 |
Correct |
105 ms |
34232 KB |
Output is correct |
10 |
Correct |
2 ms |
11352 KB |
Output is correct |
11 |
Correct |
3 ms |
11356 KB |
Output is correct |
12 |
Correct |
6 ms |
12380 KB |
Output is correct |
13 |
Correct |
7 ms |
12636 KB |
Output is correct |
14 |
Correct |
96 ms |
33908 KB |
Output is correct |
15 |
Correct |
96 ms |
33976 KB |
Output is correct |
16 |
Correct |
104 ms |
33928 KB |
Output is correct |
17 |
Correct |
94 ms |
33976 KB |
Output is correct |
18 |
Correct |
95 ms |
34032 KB |
Output is correct |
19 |
Correct |
95 ms |
33932 KB |
Output is correct |
20 |
Correct |
95 ms |
33980 KB |
Output is correct |
21 |
Correct |
98 ms |
34076 KB |
Output is correct |
22 |
Correct |
94 ms |
33932 KB |
Output is correct |
23 |
Correct |
95 ms |
33976 KB |
Output is correct |
24 |
Correct |
96 ms |
33980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
11352 KB |
Output is correct |
2 |
Correct |
183 ms |
124076 KB |
Output is correct |
3 |
Correct |
155 ms |
106768 KB |
Output is correct |
4 |
Correct |
159 ms |
105548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
11400 KB |
Output is correct |
2 |
Correct |
3 ms |
11352 KB |
Output is correct |
3 |
Correct |
3 ms |
11352 KB |
Output is correct |
4 |
Correct |
3 ms |
11356 KB |
Output is correct |
5 |
Correct |
2 ms |
11356 KB |
Output is correct |
6 |
Correct |
3 ms |
11356 KB |
Output is correct |
7 |
Correct |
2 ms |
11356 KB |
Output is correct |
8 |
Correct |
3 ms |
11356 KB |
Output is correct |
9 |
Correct |
3 ms |
11352 KB |
Output is correct |
10 |
Correct |
3 ms |
11356 KB |
Output is correct |
11 |
Correct |
4 ms |
11216 KB |
Output is correct |
12 |
Correct |
2 ms |
11200 KB |
Output is correct |
13 |
Correct |
3 ms |
11356 KB |
Output is correct |
14 |
Correct |
4 ms |
11356 KB |
Output is correct |
15 |
Correct |
3 ms |
11356 KB |
Output is correct |
16 |
Correct |
3 ms |
11356 KB |
Output is correct |
17 |
Correct |
3 ms |
11452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
11352 KB |
Output is correct |
2 |
Correct |
3 ms |
11352 KB |
Output is correct |
3 |
Correct |
4 ms |
11356 KB |
Output is correct |
4 |
Correct |
4 ms |
11608 KB |
Output is correct |
5 |
Correct |
54 ms |
47368 KB |
Output is correct |
6 |
Correct |
92 ms |
73292 KB |
Output is correct |
7 |
Correct |
129 ms |
98860 KB |
Output is correct |
8 |
Correct |
154 ms |
118188 KB |
Output is correct |
9 |
Correct |
187 ms |
130332 KB |
Output is correct |
10 |
Correct |
158 ms |
121940 KB |
Output is correct |
11 |
Correct |
4 ms |
11356 KB |
Output is correct |
12 |
Correct |
188 ms |
134804 KB |
Output is correct |
13 |
Correct |
85 ms |
64416 KB |
Output is correct |
14 |
Runtime error |
439 ms |
262144 KB |
Execution killed with signal 9 |
15 |
Halted |
0 ms |
0 KB |
- |