답안 #47695

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47695 2018-05-06T10:16:00 Z square1001 Fireworks (APIO16_fireworks) C++14
55 / 100
2000 ms 268180 KB
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, M, p[300009], c[300009], deg[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];
		deg[--p[i]]++;
		sum += c[i];
	}
	for (int i = N + M - 1; i >= 0; i--) {
		if (i >= N) {
			v[i].push_back(c[i]);
			v[i].push_back(c[i]);
		}
		else {
			sort(v[i].begin(), v[i].end());
			for (int j = 0; j < deg[i] - 1; j++) v[i].pop_back();
			v[i][v[i].size() - 1] += c[i];
			v[i][v[i].size() - 2] += c[i];
		}
		if (i != 0) {
			v[p[i]].insert(v[p[i]].end(), v[i].begin(), v[i].end());
		}
	}
	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:31:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v[0].size(); i++) {
                  ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 7 ms 7528 KB Output is correct
3 Correct 7 ms 7528 KB Output is correct
4 Correct 7 ms 7528 KB Output is correct
5 Correct 7 ms 7528 KB Output is correct
6 Correct 7 ms 7528 KB Output is correct
7 Correct 7 ms 7532 KB Output is correct
8 Correct 7 ms 7588 KB Output is correct
9 Correct 7 ms 7588 KB Output is correct
10 Correct 7 ms 7588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7588 KB Output is correct
2 Correct 8 ms 7588 KB Output is correct
3 Correct 7 ms 7628 KB Output is correct
4 Correct 8 ms 7628 KB Output is correct
5 Correct 7 ms 7628 KB Output is correct
6 Correct 8 ms 7636 KB Output is correct
7 Correct 8 ms 7764 KB Output is correct
8 Correct 7 ms 7764 KB Output is correct
9 Correct 8 ms 7764 KB Output is correct
10 Correct 8 ms 7764 KB Output is correct
11 Correct 7 ms 7764 KB Output is correct
12 Correct 7 ms 7764 KB Output is correct
13 Correct 8 ms 7764 KB Output is correct
14 Correct 8 ms 7764 KB Output is correct
15 Correct 7 ms 7764 KB Output is correct
16 Correct 7 ms 7764 KB Output is correct
17 Correct 8 ms 7764 KB Output is correct
18 Correct 8 ms 7764 KB Output is correct
19 Correct 7 ms 7764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 7 ms 7528 KB Output is correct
3 Correct 7 ms 7528 KB Output is correct
4 Correct 7 ms 7528 KB Output is correct
5 Correct 7 ms 7528 KB Output is correct
6 Correct 7 ms 7528 KB Output is correct
7 Correct 7 ms 7532 KB Output is correct
8 Correct 7 ms 7588 KB Output is correct
9 Correct 7 ms 7588 KB Output is correct
10 Correct 7 ms 7588 KB Output is correct
11 Correct 8 ms 7588 KB Output is correct
12 Correct 8 ms 7588 KB Output is correct
13 Correct 7 ms 7628 KB Output is correct
14 Correct 8 ms 7628 KB Output is correct
15 Correct 7 ms 7628 KB Output is correct
16 Correct 8 ms 7636 KB Output is correct
17 Correct 8 ms 7764 KB Output is correct
18 Correct 7 ms 7764 KB Output is correct
19 Correct 8 ms 7764 KB Output is correct
20 Correct 8 ms 7764 KB Output is correct
21 Correct 7 ms 7764 KB Output is correct
22 Correct 7 ms 7764 KB Output is correct
23 Correct 8 ms 7764 KB Output is correct
24 Correct 8 ms 7764 KB Output is correct
25 Correct 7 ms 7764 KB Output is correct
26 Correct 7 ms 7764 KB Output is correct
27 Correct 8 ms 7764 KB Output is correct
28 Correct 8 ms 7764 KB Output is correct
29 Correct 7 ms 7764 KB Output is correct
30 Correct 8 ms 7764 KB Output is correct
31 Correct 9 ms 7808 KB Output is correct
32 Correct 9 ms 7964 KB Output is correct
33 Correct 9 ms 8060 KB Output is correct
34 Correct 10 ms 8188 KB Output is correct
35 Correct 14 ms 8700 KB Output is correct
36 Correct 14 ms 8700 KB Output is correct
37 Correct 13 ms 8700 KB Output is correct
38 Correct 23 ms 9724 KB Output is correct
39 Correct 13 ms 9724 KB Output is correct
40 Correct 9 ms 9724 KB Output is correct
41 Correct 10 ms 9724 KB Output is correct
42 Correct 9 ms 9724 KB Output is correct
43 Correct 238 ms 32404 KB Output is correct
44 Correct 186 ms 32404 KB Output is correct
45 Correct 187 ms 32404 KB Output is correct
46 Correct 10 ms 32404 KB Output is correct
47 Correct 10 ms 32404 KB Output is correct
48 Correct 10 ms 32404 KB Output is correct
49 Correct 10 ms 32404 KB Output is correct
50 Correct 9 ms 32404 KB Output is correct
51 Correct 9 ms 32404 KB Output is correct
52 Correct 13 ms 32404 KB Output is correct
53 Correct 11 ms 32404 KB Output is correct
54 Correct 10 ms 32404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 7 ms 7528 KB Output is correct
3 Correct 7 ms 7528 KB Output is correct
4 Correct 7 ms 7528 KB Output is correct
5 Correct 7 ms 7528 KB Output is correct
6 Correct 7 ms 7528 KB Output is correct
7 Correct 7 ms 7532 KB Output is correct
8 Correct 7 ms 7588 KB Output is correct
9 Correct 7 ms 7588 KB Output is correct
10 Correct 7 ms 7588 KB Output is correct
11 Correct 8 ms 7588 KB Output is correct
12 Correct 8 ms 7588 KB Output is correct
13 Correct 7 ms 7628 KB Output is correct
14 Correct 8 ms 7628 KB Output is correct
15 Correct 7 ms 7628 KB Output is correct
16 Correct 8 ms 7636 KB Output is correct
17 Correct 8 ms 7764 KB Output is correct
18 Correct 7 ms 7764 KB Output is correct
19 Correct 8 ms 7764 KB Output is correct
20 Correct 8 ms 7764 KB Output is correct
21 Correct 7 ms 7764 KB Output is correct
22 Correct 7 ms 7764 KB Output is correct
23 Correct 8 ms 7764 KB Output is correct
24 Correct 8 ms 7764 KB Output is correct
25 Correct 7 ms 7764 KB Output is correct
26 Correct 7 ms 7764 KB Output is correct
27 Correct 8 ms 7764 KB Output is correct
28 Correct 8 ms 7764 KB Output is correct
29 Correct 7 ms 7764 KB Output is correct
30 Correct 8 ms 7764 KB Output is correct
31 Correct 9 ms 7808 KB Output is correct
32 Correct 9 ms 7964 KB Output is correct
33 Correct 9 ms 8060 KB Output is correct
34 Correct 10 ms 8188 KB Output is correct
35 Correct 14 ms 8700 KB Output is correct
36 Correct 14 ms 8700 KB Output is correct
37 Correct 13 ms 8700 KB Output is correct
38 Correct 23 ms 9724 KB Output is correct
39 Correct 13 ms 9724 KB Output is correct
40 Correct 9 ms 9724 KB Output is correct
41 Correct 10 ms 9724 KB Output is correct
42 Correct 9 ms 9724 KB Output is correct
43 Correct 238 ms 32404 KB Output is correct
44 Correct 186 ms 32404 KB Output is correct
45 Correct 187 ms 32404 KB Output is correct
46 Correct 10 ms 32404 KB Output is correct
47 Correct 10 ms 32404 KB Output is correct
48 Correct 10 ms 32404 KB Output is correct
49 Correct 10 ms 32404 KB Output is correct
50 Correct 9 ms 32404 KB Output is correct
51 Correct 9 ms 32404 KB Output is correct
52 Correct 13 ms 32404 KB Output is correct
53 Correct 11 ms 32404 KB Output is correct
54 Correct 10 ms 32404 KB Output is correct
55 Correct 42 ms 32404 KB Output is correct
56 Correct 354 ms 54812 KB Output is correct
57 Correct 727 ms 103628 KB Output is correct
58 Correct 829 ms 118908 KB Output is correct
59 Execution timed out 2069 ms 268180 KB Time limit exceeded
60 Halted 0 ms 0 KB -