# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
403726 | 2021-05-13T11:47:02 Z | CursedCode | Fireworks (APIO16_fireworks) | C++14 | 1 ms | 332 KB |
#include <stdio.h> #include <algorithm> #include <queue> using namespace std; const int maxn = 300003; priority_queue<long long> *Q[maxn]; int N,M,V,P[maxn],C[maxn],D[maxn]; long long E[maxn]; int main() { scanf ("%d %d",&N,&M); V = N + M; if(N != 1){ return 0; } for (int i=2;i<=V;i++) scanf ("%d %d",&P[i],&C[i]); for (int i=1;i<=V;i++) Q[i] = new priority_queue<long long>; for (int i=V;i>=2;i--){ long long p = 0, q = 0; if (D[i]){ for (int j=1;j<D[i];j++){ E[i] += Q[i]->top(); Q[i]->pop(); } p = Q[i]->top(); Q[i]->pop(); q = Q[i]->top(); Q[i]->pop(); } Q[i]->push(p+C[i]); Q[i]->push(q+C[i]); E[i] -= C[i]; priority_queue<long long> *&a = Q[i], *&b = Q[P[i]]; if (a->size() > b->size()) swap(a,b); while (!a->empty()){ b->push(a->top()); a->pop(); } E[P[i]] += E[i]; D[P[i]]++; } long long ans = E[1]; for (int i=0;i<D[1];i++){ ans += Q[1]->top(); Q[1]->pop(); } printf ("%lld\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 292 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 292 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Incorrect | 1 ms | 204 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 292 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Incorrect | 1 ms | 204 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |