# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47697 | 2018-05-06T10:29:13 Z | square1001 | Fireworks (APIO16_fireworks) | C++14 | 26 ms | 29028 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] = 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[i].begin(), v[i].end()); v[i].resize(v[i].size() - g[i].size() + 1); v[i][v[i].size() - 1] += c[i]; v[i][v[i].size() - 2] += c[i]; } for (int i = 0; i < v[0].size(); i++) { sum -= (v[0][i] - (i == 0 ? 0 : v[0][i - 1])) * (v[0].size() - i - 1); } cout << sum << '\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 14456 KB | Output is correct |
2 | Correct | 13 ms | 14512 KB | Output is correct |
3 | Correct | 15 ms | 14512 KB | Output is correct |
4 | Correct | 13 ms | 14576 KB | Output is correct |
5 | Correct | 13 ms | 14576 KB | Output is correct |
6 | Correct | 14 ms | 14636 KB | Output is correct |
7 | Correct | 13 ms | 14680 KB | Output is correct |
8 | Correct | 12 ms | 14680 KB | Output is correct |
9 | Correct | 13 ms | 14680 KB | Output is correct |
10 | Correct | 13 ms | 14680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 26 ms | 29028 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 14456 KB | Output is correct |
2 | Correct | 13 ms | 14512 KB | Output is correct |
3 | Correct | 15 ms | 14512 KB | Output is correct |
4 | Correct | 13 ms | 14576 KB | Output is correct |
5 | Correct | 13 ms | 14576 KB | Output is correct |
6 | Correct | 14 ms | 14636 KB | Output is correct |
7 | Correct | 13 ms | 14680 KB | Output is correct |
8 | Correct | 12 ms | 14680 KB | Output is correct |
9 | Correct | 13 ms | 14680 KB | Output is correct |
10 | Correct | 13 ms | 14680 KB | Output is correct |
11 | Runtime error | 26 ms | 29028 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 14456 KB | Output is correct |
2 | Correct | 13 ms | 14512 KB | Output is correct |
3 | Correct | 15 ms | 14512 KB | Output is correct |
4 | Correct | 13 ms | 14576 KB | Output is correct |
5 | Correct | 13 ms | 14576 KB | Output is correct |
6 | Correct | 14 ms | 14636 KB | Output is correct |
7 | Correct | 13 ms | 14680 KB | Output is correct |
8 | Correct | 12 ms | 14680 KB | Output is correct |
9 | Correct | 13 ms | 14680 KB | Output is correct |
10 | Correct | 13 ms | 14680 KB | Output is correct |
11 | Runtime error | 26 ms | 29028 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
12 | Halted | 0 ms | 0 KB | - |