답안 #969988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
969988 2024-04-26T03:31:31 Z bachhoangxuan Fireworks (APIO16_fireworks) C++17
100 / 100
142 ms 48044 KB
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const long long inf=1e18;
const int mod=998244353;
const int maxn=300005;
const int B=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=25;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
const int iroot=power(3,mod-2);
const int base=101;

int n,m;
int c[maxn],p[maxn];
int a[maxn],b[maxn];
priority_queue<int> pq[maxn];

void merge(int u,int v){
    a[u]+=a[v];b[u]+=b[v];
    if((int)pq[u].size()<(int)pq[v].size()) pq[u].swap(pq[v]);
    while(!pq[v].empty()){
        pq[u].push(pq[v].top());
        pq[v].pop();
    }
}

void solve(){
    cin >> n >> m;
    for(int i=2;i<=n+m;i++) cin >> p[i] >> c[i];
    for(int i=n+1;i<=n+m;i++){
        a[i]=1;
        b[i]=-c[i];
        pq[i].push(c[i]);
        pq[i].push(c[i]);
        merge(p[i],i);
    }
    for(int i=n;i>=2;i--){
        while(a[i]>1){
            b[i]+=pq[i].top();
            a[i]--;pq[i].pop();
        }
        int t0=pq[i].top();pq[i].pop();
        int t1=pq[i].top();pq[i].pop();
        pq[i].push(t0+c[i]);pq[i].push(t1+c[i]);
        b[i]-=c[i];merge(p[i],i);
    }
    while(a[1]>0){
        b[1]+=pq[1].top();
        a[1]--;pq[1].pop();
    }
    cout << b[1] << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 4 ms 17144 KB Output is correct
3 Correct 4 ms 16988 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 5 ms 16988 KB Output is correct
6 Correct 4 ms 17140 KB Output is correct
7 Correct 5 ms 16984 KB Output is correct
8 Correct 4 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 3 ms 17040 KB Output is correct
3 Correct 3 ms 16988 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 3 ms 16984 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 17012 KB Output is correct
9 Correct 4 ms 16984 KB Output is correct
10 Correct 3 ms 17048 KB Output is correct
11 Correct 3 ms 16988 KB Output is correct
12 Correct 3 ms 16988 KB Output is correct
13 Correct 4 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
16 Correct 3 ms 16988 KB Output is correct
17 Correct 3 ms 16996 KB Output is correct
18 Correct 3 ms 16988 KB Output is correct
19 Correct 3 ms 17004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 4 ms 17144 KB Output is correct
3 Correct 4 ms 16988 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 5 ms 16988 KB Output is correct
6 Correct 4 ms 17140 KB Output is correct
7 Correct 5 ms 16984 KB Output is correct
8 Correct 4 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
11 Correct 3 ms 16988 KB Output is correct
12 Correct 3 ms 17040 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 16984 KB Output is correct
16 Correct 3 ms 16988 KB Output is correct
17 Correct 3 ms 16988 KB Output is correct
18 Correct 3 ms 17012 KB Output is correct
19 Correct 4 ms 16984 KB Output is correct
20 Correct 3 ms 17048 KB Output is correct
21 Correct 3 ms 16988 KB Output is correct
22 Correct 3 ms 16988 KB Output is correct
23 Correct 4 ms 16988 KB Output is correct
24 Correct 3 ms 16988 KB Output is correct
25 Correct 3 ms 16988 KB Output is correct
26 Correct 3 ms 16988 KB Output is correct
27 Correct 3 ms 16996 KB Output is correct
28 Correct 3 ms 16988 KB Output is correct
29 Correct 3 ms 17004 KB Output is correct
30 Correct 3 ms 16984 KB Output is correct
31 Correct 3 ms 16988 KB Output is correct
32 Correct 4 ms 17072 KB Output is correct
33 Correct 4 ms 16988 KB Output is correct
34 Correct 4 ms 16988 KB Output is correct
35 Correct 4 ms 17208 KB Output is correct
36 Correct 4 ms 17244 KB Output is correct
37 Correct 4 ms 17244 KB Output is correct
38 Correct 5 ms 17244 KB Output is correct
39 Correct 5 ms 17244 KB Output is correct
40 Correct 5 ms 16988 KB Output is correct
41 Correct 4 ms 16984 KB Output is correct
42 Correct 4 ms 16988 KB Output is correct
43 Correct 5 ms 17244 KB Output is correct
44 Correct 5 ms 17264 KB Output is correct
45 Correct 5 ms 17240 KB Output is correct
46 Correct 6 ms 17240 KB Output is correct
47 Correct 6 ms 17496 KB Output is correct
48 Correct 6 ms 17244 KB Output is correct
49 Correct 5 ms 17244 KB Output is correct
50 Correct 5 ms 17244 KB Output is correct
51 Correct 4 ms 17240 KB Output is correct
52 Correct 5 ms 17240 KB Output is correct
53 Correct 5 ms 17308 KB Output is correct
54 Correct 5 ms 17244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 4 ms 17144 KB Output is correct
3 Correct 4 ms 16988 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 5 ms 16988 KB Output is correct
6 Correct 4 ms 17140 KB Output is correct
7 Correct 5 ms 16984 KB Output is correct
8 Correct 4 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
11 Correct 3 ms 16988 KB Output is correct
12 Correct 3 ms 17040 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 16984 KB Output is correct
16 Correct 3 ms 16988 KB Output is correct
17 Correct 3 ms 16988 KB Output is correct
18 Correct 3 ms 17012 KB Output is correct
19 Correct 4 ms 16984 KB Output is correct
20 Correct 3 ms 17048 KB Output is correct
21 Correct 3 ms 16988 KB Output is correct
22 Correct 3 ms 16988 KB Output is correct
23 Correct 4 ms 16988 KB Output is correct
24 Correct 3 ms 16988 KB Output is correct
25 Correct 3 ms 16988 KB Output is correct
26 Correct 3 ms 16988 KB Output is correct
27 Correct 3 ms 16996 KB Output is correct
28 Correct 3 ms 16988 KB Output is correct
29 Correct 3 ms 17004 KB Output is correct
30 Correct 3 ms 16984 KB Output is correct
31 Correct 3 ms 16988 KB Output is correct
32 Correct 4 ms 17072 KB Output is correct
33 Correct 4 ms 16988 KB Output is correct
34 Correct 4 ms 16988 KB Output is correct
35 Correct 4 ms 17208 KB Output is correct
36 Correct 4 ms 17244 KB Output is correct
37 Correct 4 ms 17244 KB Output is correct
38 Correct 5 ms 17244 KB Output is correct
39 Correct 5 ms 17244 KB Output is correct
40 Correct 5 ms 16988 KB Output is correct
41 Correct 4 ms 16984 KB Output is correct
42 Correct 4 ms 16988 KB Output is correct
43 Correct 5 ms 17244 KB Output is correct
44 Correct 5 ms 17264 KB Output is correct
45 Correct 5 ms 17240 KB Output is correct
46 Correct 6 ms 17240 KB Output is correct
47 Correct 6 ms 17496 KB Output is correct
48 Correct 6 ms 17244 KB Output is correct
49 Correct 5 ms 17244 KB Output is correct
50 Correct 5 ms 17244 KB Output is correct
51 Correct 4 ms 17240 KB Output is correct
52 Correct 5 ms 17240 KB Output is correct
53 Correct 5 ms 17308 KB Output is correct
54 Correct 5 ms 17244 KB Output is correct
55 Correct 7 ms 17500 KB Output is correct
56 Correct 19 ms 21644 KB Output is correct
57 Correct 40 ms 23664 KB Output is correct
58 Correct 38 ms 24576 KB Output is correct
59 Correct 50 ms 26344 KB Output is correct
60 Correct 62 ms 28108 KB Output is correct
61 Correct 80 ms 29852 KB Output is correct
62 Correct 91 ms 30804 KB Output is correct
63 Correct 99 ms 33100 KB Output is correct
64 Correct 102 ms 33608 KB Output is correct
65 Correct 49 ms 23888 KB Output is correct
66 Correct 47 ms 23892 KB Output is correct
67 Correct 49 ms 24148 KB Output is correct
68 Correct 94 ms 30652 KB Output is correct
69 Correct 99 ms 31432 KB Output is correct
70 Correct 99 ms 31384 KB Output is correct
71 Correct 142 ms 48044 KB Output is correct
72 Correct 132 ms 47420 KB Output is correct
73 Correct 114 ms 43716 KB Output is correct
74 Correct 119 ms 44660 KB Output is correct
75 Correct 116 ms 41920 KB Output is correct
76 Correct 115 ms 43688 KB Output is correct
77 Correct 136 ms 42484 KB Output is correct
78 Correct 131 ms 40668 KB Output is correct
79 Correct 117 ms 39264 KB Output is correct