# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
47699 | 2018-05-06T10:31:15 Z | square1001 | Fireworks (APIO16_fireworks) | C++14 | 14 ms | 14804 KB |
#include <vector> #include <iostream> #include <algorithm> using namespace std; int N, M, p[300009], c[300009], id[300009]; vector<int> g[300009]; vector<long long> v[300009]; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cin >> N >> M; long long sum = 0; for (int i = 1; i < N + M; i++) { cin >> p[i] >> c[i]; g[--p[i]].push_back(i); sum += c[i]; if (i >= N) { v[i - N].push_back(c[i]); v[i - N].push_back(c[i]); id[i] = i - N; } } for (int i = N - 1; i >= 0; i--) { int mx = -1; for (int j : g[i]) { if (mx < v[id[j]].size()) { mx = v[id[j]].size(); id[i] = id[j]; } } for (int j : g[i]) { if (id[j] != id[i]) { v[id[i]].insert(v[id[i]].end(), v[id[j]].begin(), v[id[j]].end()); } } sort(v[id[i]].begin(), v[id[i]].end()); v[id[i]].resize(v[id[i]].size() - g[i].size() + 1); v[id[i]][v[id[i]].size() - 1] += c[i]; v[id[i]][v[id[i]].size() - 2] += c[i]; } for (int i = 0; i < v[id[0]].size(); i++) { sum -= (v[id[0]][i] - (i == 0 ? 0 : v[id[0]][i - 1])) * (v[id[0]].size() - i - 1); } cout << sum << '\n'; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 14460 KB | Output is correct |
2 | Correct | 13 ms | 14516 KB | Output is correct |
3 | Correct | 14 ms | 14584 KB | Output is correct |
4 | Correct | 13 ms | 14592 KB | Output is correct |
5 | Correct | 13 ms | 14592 KB | Output is correct |
6 | Correct | 13 ms | 14620 KB | Output is correct |
7 | Correct | 13 ms | 14704 KB | Output is correct |
8 | Correct | 13 ms | 14704 KB | Output is correct |
9 | Correct | 13 ms | 14804 KB | Output is correct |
10 | Correct | 13 ms | 14804 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 14 ms | 14804 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 14460 KB | Output is correct |
2 | Correct | 13 ms | 14516 KB | Output is correct |
3 | Correct | 14 ms | 14584 KB | Output is correct |
4 | Correct | 13 ms | 14592 KB | Output is correct |
5 | Correct | 13 ms | 14592 KB | Output is correct |
6 | Correct | 13 ms | 14620 KB | Output is correct |
7 | Correct | 13 ms | 14704 KB | Output is correct |
8 | Correct | 13 ms | 14704 KB | Output is correct |
9 | Correct | 13 ms | 14804 KB | Output is correct |
10 | Correct | 13 ms | 14804 KB | Output is correct |
11 | Incorrect | 14 ms | 14804 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 14460 KB | Output is correct |
2 | Correct | 13 ms | 14516 KB | Output is correct |
3 | Correct | 14 ms | 14584 KB | Output is correct |
4 | Correct | 13 ms | 14592 KB | Output is correct |
5 | Correct | 13 ms | 14592 KB | Output is correct |
6 | Correct | 13 ms | 14620 KB | Output is correct |
7 | Correct | 13 ms | 14704 KB | Output is correct |
8 | Correct | 13 ms | 14704 KB | Output is correct |
9 | Correct | 13 ms | 14804 KB | Output is correct |
10 | Correct | 13 ms | 14804 KB | Output is correct |
11 | Incorrect | 14 ms | 14804 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |