# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
329218 | Nirjhor | Fireworks (APIO16_fireworks) | C++17 | 7 ms | 7404 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 300010;
int n, m, p[N];
vector <int> g[N];
ll w[N], a[N], b[N];
priority_queue <ll> *pq[N];
int main() {
cin >> m >> n; n += m;
for (int i = 2; i <= n; ++i) {
scanf("%d %lld", p + i, w + i);
g[p[i]].emplace_back(i);
}
for (int i = m + 1; i <= n; ++i) {
a[i] = 1, b[i] = -w[i];
pq[i] = new priority_queue <ll> ();
pq[i] -> emplace(w[i]); pq[i] -> emplace(w[i]);
}
for (int i = m; i >= 2; --i) {
pq[i] = new priority_queue <ll> ();
for (int j : g[i]) {
if (pq[j] -> size() > pq[i] -> size()) swap(pq[i], pq[j]);
while (!(pq[j] -> empty())) pq[i] -> emplace(pq[j] -> top()), pq[j] -> pop();
a[i] += a[j], b[i] += b[j];
}
while (a[i] > 1) b[i] += pq[i] -> top(), --a[i], pq[i] -> pop(); b[i] -= w[i];
ll one = pq[i] -> top(); pq[i] -> pop();
ll two = pq[i] -> top(); pq[i] -> pop();
pq[i] -> emplace(one + w[i]); pq[i] -> emplace(two + w[i]);
}
cout << a[2] * pq[2] -> top() + b[2] << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |