Submission #47696

# Submission time Handle Problem Language Result Execution time Memory
47696 2018-05-06T10:24:22 Z square1001 Fireworks (APIO16_fireworks) C++14
55 / 100
2000 ms 524288 KB
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, M, p[300009], c[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].push_back(c[i]);
			v[i].push_back(c[i]);
		}
	}
	for (int i = N - 1; i >= 0; i--) {
		for (int j : g[i]) {
			v[i].insert(v[i].end(), v[j].begin(), v[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

fireworks.cpp: In function 'int main()':
fireworks.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v[0].size(); i++) {
                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14456 KB Output is correct
2 Correct 12 ms 14612 KB Output is correct
3 Correct 12 ms 14612 KB Output is correct
4 Correct 14 ms 14612 KB Output is correct
5 Correct 13 ms 14636 KB Output is correct
6 Correct 13 ms 14728 KB Output is correct
7 Correct 14 ms 14728 KB Output is correct
8 Correct 13 ms 14728 KB Output is correct
9 Correct 13 ms 14728 KB Output is correct
10 Correct 13 ms 14728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14728 KB Output is correct
2 Correct 13 ms 14728 KB Output is correct
3 Correct 13 ms 14728 KB Output is correct
4 Correct 13 ms 14728 KB Output is correct
5 Correct 13 ms 14728 KB Output is correct
6 Correct 12 ms 14728 KB Output is correct
7 Correct 13 ms 14728 KB Output is correct
8 Correct 13 ms 14728 KB Output is correct
9 Correct 13 ms 14728 KB Output is correct
10 Correct 13 ms 14728 KB Output is correct
11 Correct 13 ms 14728 KB Output is correct
12 Correct 13 ms 14728 KB Output is correct
13 Correct 12 ms 14728 KB Output is correct
14 Correct 13 ms 14728 KB Output is correct
15 Correct 13 ms 14728 KB Output is correct
16 Correct 13 ms 14728 KB Output is correct
17 Correct 13 ms 14728 KB Output is correct
18 Correct 13 ms 14728 KB Output is correct
19 Correct 13 ms 14728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14456 KB Output is correct
2 Correct 12 ms 14612 KB Output is correct
3 Correct 12 ms 14612 KB Output is correct
4 Correct 14 ms 14612 KB Output is correct
5 Correct 13 ms 14636 KB Output is correct
6 Correct 13 ms 14728 KB Output is correct
7 Correct 14 ms 14728 KB Output is correct
8 Correct 13 ms 14728 KB Output is correct
9 Correct 13 ms 14728 KB Output is correct
10 Correct 13 ms 14728 KB Output is correct
11 Correct 12 ms 14728 KB Output is correct
12 Correct 13 ms 14728 KB Output is correct
13 Correct 13 ms 14728 KB Output is correct
14 Correct 13 ms 14728 KB Output is correct
15 Correct 13 ms 14728 KB Output is correct
16 Correct 12 ms 14728 KB Output is correct
17 Correct 13 ms 14728 KB Output is correct
18 Correct 13 ms 14728 KB Output is correct
19 Correct 13 ms 14728 KB Output is correct
20 Correct 13 ms 14728 KB Output is correct
21 Correct 13 ms 14728 KB Output is correct
22 Correct 13 ms 14728 KB Output is correct
23 Correct 12 ms 14728 KB Output is correct
24 Correct 13 ms 14728 KB Output is correct
25 Correct 13 ms 14728 KB Output is correct
26 Correct 13 ms 14728 KB Output is correct
27 Correct 13 ms 14728 KB Output is correct
28 Correct 13 ms 14728 KB Output is correct
29 Correct 13 ms 14728 KB Output is correct
30 Correct 13 ms 14728 KB Output is correct
31 Correct 14 ms 14972 KB Output is correct
32 Correct 14 ms 14972 KB Output is correct
33 Correct 15 ms 15356 KB Output is correct
34 Correct 16 ms 15564 KB Output is correct
35 Correct 18 ms 16512 KB Output is correct
36 Correct 18 ms 16512 KB Output is correct
37 Correct 18 ms 16512 KB Output is correct
38 Correct 24 ms 18172 KB Output is correct
39 Correct 19 ms 18172 KB Output is correct
40 Correct 15 ms 18172 KB Output is correct
41 Correct 15 ms 18172 KB Output is correct
42 Correct 15 ms 18172 KB Output is correct
43 Correct 128 ms 60644 KB Output is correct
44 Correct 109 ms 60644 KB Output is correct
45 Correct 110 ms 60644 KB Output is correct
46 Correct 17 ms 60644 KB Output is correct
47 Correct 19 ms 60644 KB Output is correct
48 Correct 15 ms 60644 KB Output is correct
49 Correct 16 ms 60644 KB Output is correct
50 Correct 16 ms 60644 KB Output is correct
51 Correct 15 ms 60644 KB Output is correct
52 Correct 17 ms 60644 KB Output is correct
53 Correct 16 ms 60644 KB Output is correct
54 Correct 16 ms 60644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14456 KB Output is correct
2 Correct 12 ms 14612 KB Output is correct
3 Correct 12 ms 14612 KB Output is correct
4 Correct 14 ms 14612 KB Output is correct
5 Correct 13 ms 14636 KB Output is correct
6 Correct 13 ms 14728 KB Output is correct
7 Correct 14 ms 14728 KB Output is correct
8 Correct 13 ms 14728 KB Output is correct
9 Correct 13 ms 14728 KB Output is correct
10 Correct 13 ms 14728 KB Output is correct
11 Correct 12 ms 14728 KB Output is correct
12 Correct 13 ms 14728 KB Output is correct
13 Correct 13 ms 14728 KB Output is correct
14 Correct 13 ms 14728 KB Output is correct
15 Correct 13 ms 14728 KB Output is correct
16 Correct 12 ms 14728 KB Output is correct
17 Correct 13 ms 14728 KB Output is correct
18 Correct 13 ms 14728 KB Output is correct
19 Correct 13 ms 14728 KB Output is correct
20 Correct 13 ms 14728 KB Output is correct
21 Correct 13 ms 14728 KB Output is correct
22 Correct 13 ms 14728 KB Output is correct
23 Correct 12 ms 14728 KB Output is correct
24 Correct 13 ms 14728 KB Output is correct
25 Correct 13 ms 14728 KB Output is correct
26 Correct 13 ms 14728 KB Output is correct
27 Correct 13 ms 14728 KB Output is correct
28 Correct 13 ms 14728 KB Output is correct
29 Correct 13 ms 14728 KB Output is correct
30 Correct 13 ms 14728 KB Output is correct
31 Correct 14 ms 14972 KB Output is correct
32 Correct 14 ms 14972 KB Output is correct
33 Correct 15 ms 15356 KB Output is correct
34 Correct 16 ms 15564 KB Output is correct
35 Correct 18 ms 16512 KB Output is correct
36 Correct 18 ms 16512 KB Output is correct
37 Correct 18 ms 16512 KB Output is correct
38 Correct 24 ms 18172 KB Output is correct
39 Correct 19 ms 18172 KB Output is correct
40 Correct 15 ms 18172 KB Output is correct
41 Correct 15 ms 18172 KB Output is correct
42 Correct 15 ms 18172 KB Output is correct
43 Correct 128 ms 60644 KB Output is correct
44 Correct 109 ms 60644 KB Output is correct
45 Correct 110 ms 60644 KB Output is correct
46 Correct 17 ms 60644 KB Output is correct
47 Correct 19 ms 60644 KB Output is correct
48 Correct 15 ms 60644 KB Output is correct
49 Correct 16 ms 60644 KB Output is correct
50 Correct 16 ms 60644 KB Output is correct
51 Correct 15 ms 60644 KB Output is correct
52 Correct 17 ms 60644 KB Output is correct
53 Correct 16 ms 60644 KB Output is correct
54 Correct 16 ms 60644 KB Output is correct
55 Correct 40 ms 60644 KB Output is correct
56 Correct 242 ms 67904 KB Output is correct
57 Correct 480 ms 121704 KB Output is correct
58 Correct 555 ms 144328 KB Output is correct
59 Correct 1251 ms 291596 KB Output is correct
60 Correct 1226 ms 295584 KB Output is correct
61 Execution timed out 2140 ms 524288 KB Time limit exceeded
62 Halted 0 ms 0 KB -