답안 #47701

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47701 2018-05-06T10:39:43 Z square1001 Fireworks (APIO16_fireworks) C++14
55 / 100
2000 ms 59100 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 = 0;
		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

fireworks.cpp: In function 'int main()':
fireworks.cpp:24:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (mx < v[id[j]].size()) {
        ~~~^~~~~~~~~~~~~~~~~
fireworks.cpp:39:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v[id[0]].size(); i++) {
                  ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14456 KB Output is correct
2 Correct 12 ms 14456 KB Output is correct
3 Correct 12 ms 14508 KB Output is correct
4 Correct 12 ms 14584 KB Output is correct
5 Correct 12 ms 14640 KB Output is correct
6 Correct 13 ms 14652 KB Output is correct
7 Correct 13 ms 14652 KB Output is correct
8 Correct 12 ms 14716 KB Output is correct
9 Correct 12 ms 14716 KB Output is correct
10 Correct 13 ms 14760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 14760 KB Output is correct
2 Correct 14 ms 14760 KB Output is correct
3 Correct 12 ms 14760 KB Output is correct
4 Correct 13 ms 14760 KB Output is correct
5 Correct 13 ms 14760 KB Output is correct
6 Correct 13 ms 14760 KB Output is correct
7 Correct 13 ms 14760 KB Output is correct
8 Correct 12 ms 14760 KB Output is correct
9 Correct 13 ms 14760 KB Output is correct
10 Correct 13 ms 14760 KB Output is correct
11 Correct 13 ms 14760 KB Output is correct
12 Correct 13 ms 14768 KB Output is correct
13 Correct 13 ms 14848 KB Output is correct
14 Correct 13 ms 14848 KB Output is correct
15 Correct 13 ms 14848 KB Output is correct
16 Correct 13 ms 14848 KB Output is correct
17 Correct 13 ms 14848 KB Output is correct
18 Correct 12 ms 14848 KB Output is correct
19 Correct 13 ms 14848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14456 KB Output is correct
2 Correct 12 ms 14456 KB Output is correct
3 Correct 12 ms 14508 KB Output is correct
4 Correct 12 ms 14584 KB Output is correct
5 Correct 12 ms 14640 KB Output is correct
6 Correct 13 ms 14652 KB Output is correct
7 Correct 13 ms 14652 KB Output is correct
8 Correct 12 ms 14716 KB Output is correct
9 Correct 12 ms 14716 KB Output is correct
10 Correct 13 ms 14760 KB Output is correct
11 Correct 12 ms 14760 KB Output is correct
12 Correct 14 ms 14760 KB Output is correct
13 Correct 12 ms 14760 KB Output is correct
14 Correct 13 ms 14760 KB Output is correct
15 Correct 13 ms 14760 KB Output is correct
16 Correct 13 ms 14760 KB Output is correct
17 Correct 13 ms 14760 KB Output is correct
18 Correct 12 ms 14760 KB Output is correct
19 Correct 13 ms 14760 KB Output is correct
20 Correct 13 ms 14760 KB Output is correct
21 Correct 13 ms 14760 KB Output is correct
22 Correct 13 ms 14768 KB Output is correct
23 Correct 13 ms 14848 KB Output is correct
24 Correct 13 ms 14848 KB Output is correct
25 Correct 13 ms 14848 KB Output is correct
26 Correct 13 ms 14848 KB Output is correct
27 Correct 13 ms 14848 KB Output is correct
28 Correct 12 ms 14848 KB Output is correct
29 Correct 13 ms 14848 KB Output is correct
30 Correct 13 ms 14848 KB Output is correct
31 Correct 14 ms 14916 KB Output is correct
32 Correct 14 ms 14972 KB Output is correct
33 Correct 15 ms 14976 KB Output is correct
34 Correct 15 ms 15116 KB Output is correct
35 Correct 16 ms 15160 KB Output is correct
36 Correct 16 ms 15212 KB Output is correct
37 Correct 18 ms 15400 KB Output is correct
38 Correct 21 ms 15460 KB Output is correct
39 Correct 17 ms 15532 KB Output is correct
40 Correct 14 ms 15532 KB Output is correct
41 Correct 15 ms 15608 KB Output is correct
42 Correct 15 ms 15608 KB Output is correct
43 Correct 95 ms 15816 KB Output is correct
44 Correct 82 ms 15816 KB Output is correct
45 Correct 80 ms 15972 KB Output is correct
46 Correct 15 ms 16172 KB Output is correct
47 Correct 15 ms 16236 KB Output is correct
48 Correct 15 ms 16264 KB Output is correct
49 Correct 16 ms 16356 KB Output is correct
50 Correct 14 ms 16356 KB Output is correct
51 Correct 15 ms 16356 KB Output is correct
52 Correct 16 ms 16392 KB Output is correct
53 Correct 15 ms 16452 KB Output is correct
54 Correct 15 ms 16644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14456 KB Output is correct
2 Correct 12 ms 14456 KB Output is correct
3 Correct 12 ms 14508 KB Output is correct
4 Correct 12 ms 14584 KB Output is correct
5 Correct 12 ms 14640 KB Output is correct
6 Correct 13 ms 14652 KB Output is correct
7 Correct 13 ms 14652 KB Output is correct
8 Correct 12 ms 14716 KB Output is correct
9 Correct 12 ms 14716 KB Output is correct
10 Correct 13 ms 14760 KB Output is correct
11 Correct 12 ms 14760 KB Output is correct
12 Correct 14 ms 14760 KB Output is correct
13 Correct 12 ms 14760 KB Output is correct
14 Correct 13 ms 14760 KB Output is correct
15 Correct 13 ms 14760 KB Output is correct
16 Correct 13 ms 14760 KB Output is correct
17 Correct 13 ms 14760 KB Output is correct
18 Correct 12 ms 14760 KB Output is correct
19 Correct 13 ms 14760 KB Output is correct
20 Correct 13 ms 14760 KB Output is correct
21 Correct 13 ms 14760 KB Output is correct
22 Correct 13 ms 14768 KB Output is correct
23 Correct 13 ms 14848 KB Output is correct
24 Correct 13 ms 14848 KB Output is correct
25 Correct 13 ms 14848 KB Output is correct
26 Correct 13 ms 14848 KB Output is correct
27 Correct 13 ms 14848 KB Output is correct
28 Correct 12 ms 14848 KB Output is correct
29 Correct 13 ms 14848 KB Output is correct
30 Correct 13 ms 14848 KB Output is correct
31 Correct 14 ms 14916 KB Output is correct
32 Correct 14 ms 14972 KB Output is correct
33 Correct 15 ms 14976 KB Output is correct
34 Correct 15 ms 15116 KB Output is correct
35 Correct 16 ms 15160 KB Output is correct
36 Correct 16 ms 15212 KB Output is correct
37 Correct 18 ms 15400 KB Output is correct
38 Correct 21 ms 15460 KB Output is correct
39 Correct 17 ms 15532 KB Output is correct
40 Correct 14 ms 15532 KB Output is correct
41 Correct 15 ms 15608 KB Output is correct
42 Correct 15 ms 15608 KB Output is correct
43 Correct 95 ms 15816 KB Output is correct
44 Correct 82 ms 15816 KB Output is correct
45 Correct 80 ms 15972 KB Output is correct
46 Correct 15 ms 16172 KB Output is correct
47 Correct 15 ms 16236 KB Output is correct
48 Correct 15 ms 16264 KB Output is correct
49 Correct 16 ms 16356 KB Output is correct
50 Correct 14 ms 16356 KB Output is correct
51 Correct 15 ms 16356 KB Output is correct
52 Correct 16 ms 16392 KB Output is correct
53 Correct 15 ms 16452 KB Output is correct
54 Correct 15 ms 16644 KB Output is correct
55 Correct 32 ms 17216 KB Output is correct
56 Correct 197 ms 20480 KB Output is correct
57 Correct 405 ms 24260 KB Output is correct
58 Correct 450 ms 27496 KB Output is correct
59 Correct 1067 ms 32016 KB Output is correct
60 Correct 1040 ms 37408 KB Output is correct
61 Correct 1379 ms 41444 KB Output is correct
62 Correct 1508 ms 46876 KB Output is correct
63 Correct 1451 ms 54308 KB Output is correct
64 Execution timed out 2079 ms 59100 KB Time limit exceeded
65 Halted 0 ms 0 KB -