답안 #47692

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47692 2018-05-06T09:59:11 Z E869120 Fireworks (APIO16_fireworks) C++14
55 / 100
2000 ms 360868 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

long long N, M, A[300009], B[300009], dist[300009], sum; vector<pair<long long, long long>>x[300009];
vector<long long>G[300009];

void dfs1(int pos, long long depth) {
	dist[pos] = depth;
	for (int i = 0; i < x[pos].size(); i++) dfs1(x[pos][i].first, depth + x[pos][i].second);
}
void dfs2(int pos) {
	if (x[pos].size() == 0) { G[pos].push_back(dist[pos]); G[pos].push_back(dist[pos]); return; }

	for (int i = 0; i < x[pos].size(); i++) dfs2(x[pos][i].first);

	for (int i = 0; i < x[pos].size(); i++) {
		for (int j = 0; j < G[x[pos][i].first].size(); j++) G[pos].emplace_back(G[x[pos][i].first][j]);
	}
	sort(G[pos].begin(), G[pos].end());
	vector<long long>H;
	for (int i = 0; i < (int)G[pos].size() - (int)x[pos].size() + 1; i++) H.emplace_back(G[pos][i]);
	G[pos] = H;
	for (int i = 0; i < (int)G[pos].size() - 2; i++) G[pos][i] -= B[pos];
}

int main() {
	cin >> N >> M;
	for (int i = 2; i <= N + M; i++) {
		scanf("%lld%lld", &A[i], &B[i]); sum += B[i];
		x[A[i]].push_back(make_pair(i, B[i]));
	}
	dfs1(1, 0);
	dfs2(1);
	long long ret = sum, cx = 0, D = G[1].size() - 1;
	for (int i = 0; i < G[1].size() - 1; i++) { ret -= (G[1][i] - cx)*D; cx = G[1][i]; D--; }
	cout << ret << endl;
	return 0;
}

Compilation message

fireworks.cpp:5:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
fireworks.cpp: In function 'void dfs1(int, long long int)':
fireworks.cpp:12:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x[pos].size(); i++) dfs1(x[pos][i].first, depth + x[pos][i].second);
                  ~~^~~~~~~~~~~~~~~
fireworks.cpp: In function 'void dfs2(int)':
fireworks.cpp:17:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x[pos].size(); i++) dfs2(x[pos][i].first);
                  ~~^~~~~~~~~~~~~~~
fireworks.cpp:19:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x[pos].size(); i++) {
                  ~~^~~~~~~~~~~~~~~
fireworks.cpp:20:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < G[x[pos][i].first].size(); j++) G[pos].emplace_back(G[x[pos][i].first][j]);
                   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
fireworks.cpp: In function 'int main()':
fireworks.cpp:38:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < G[1].size() - 1; i++) { ret -= (G[1][i] - cx)*D; cx = G[1][i]; D--; }
                  ~~^~~~~~~~~~~~~~~~~
fireworks.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &A[i], &B[i]); sum += B[i];
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14584 KB Output is correct
2 Correct 13 ms 14584 KB Output is correct
3 Correct 13 ms 14584 KB Output is correct
4 Correct 12 ms 14584 KB Output is correct
5 Correct 13 ms 14584 KB Output is correct
6 Correct 13 ms 14636 KB Output is correct
7 Correct 13 ms 14648 KB Output is correct
8 Correct 13 ms 14700 KB Output is correct
9 Correct 13 ms 14800 KB Output is correct
10 Correct 14 ms 14800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 14800 KB Output is correct
2 Correct 14 ms 14800 KB Output is correct
3 Correct 15 ms 14800 KB Output is correct
4 Correct 12 ms 14800 KB Output is correct
5 Correct 15 ms 14800 KB Output is correct
6 Correct 13 ms 14800 KB Output is correct
7 Correct 13 ms 14800 KB Output is correct
8 Correct 13 ms 14800 KB Output is correct
9 Correct 13 ms 14800 KB Output is correct
10 Correct 15 ms 14800 KB Output is correct
11 Correct 13 ms 14800 KB Output is correct
12 Correct 13 ms 14800 KB Output is correct
13 Correct 13 ms 14800 KB Output is correct
14 Correct 13 ms 14800 KB Output is correct
15 Correct 14 ms 14800 KB Output is correct
16 Correct 14 ms 14800 KB Output is correct
17 Correct 14 ms 14824 KB Output is correct
18 Correct 13 ms 14824 KB Output is correct
19 Correct 14 ms 14952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14584 KB Output is correct
2 Correct 13 ms 14584 KB Output is correct
3 Correct 13 ms 14584 KB Output is correct
4 Correct 12 ms 14584 KB Output is correct
5 Correct 13 ms 14584 KB Output is correct
6 Correct 13 ms 14636 KB Output is correct
7 Correct 13 ms 14648 KB Output is correct
8 Correct 13 ms 14700 KB Output is correct
9 Correct 13 ms 14800 KB Output is correct
10 Correct 14 ms 14800 KB Output is correct
11 Correct 12 ms 14800 KB Output is correct
12 Correct 14 ms 14800 KB Output is correct
13 Correct 15 ms 14800 KB Output is correct
14 Correct 12 ms 14800 KB Output is correct
15 Correct 15 ms 14800 KB Output is correct
16 Correct 13 ms 14800 KB Output is correct
17 Correct 13 ms 14800 KB Output is correct
18 Correct 13 ms 14800 KB Output is correct
19 Correct 13 ms 14800 KB Output is correct
20 Correct 15 ms 14800 KB Output is correct
21 Correct 13 ms 14800 KB Output is correct
22 Correct 13 ms 14800 KB Output is correct
23 Correct 13 ms 14800 KB Output is correct
24 Correct 13 ms 14800 KB Output is correct
25 Correct 14 ms 14800 KB Output is correct
26 Correct 14 ms 14800 KB Output is correct
27 Correct 14 ms 14824 KB Output is correct
28 Correct 13 ms 14824 KB Output is correct
29 Correct 14 ms 14952 KB Output is correct
30 Correct 14 ms 14952 KB Output is correct
31 Correct 14 ms 15044 KB Output is correct
32 Correct 17 ms 15188 KB Output is correct
33 Correct 17 ms 15340 KB Output is correct
34 Correct 18 ms 15756 KB Output is correct
35 Correct 21 ms 16440 KB Output is correct
36 Correct 22 ms 16504 KB Output is correct
37 Correct 22 ms 16504 KB Output is correct
38 Correct 33 ms 17892 KB Output is correct
39 Correct 23 ms 17892 KB Output is correct
40 Correct 16 ms 17892 KB Output is correct
41 Correct 18 ms 17892 KB Output is correct
42 Correct 16 ms 17892 KB Output is correct
43 Correct 151 ms 46436 KB Output is correct
44 Correct 128 ms 46436 KB Output is correct
45 Correct 126 ms 46436 KB Output is correct
46 Correct 17 ms 46436 KB Output is correct
47 Correct 16 ms 46436 KB Output is correct
48 Correct 16 ms 46436 KB Output is correct
49 Correct 21 ms 46436 KB Output is correct
50 Correct 17 ms 46436 KB Output is correct
51 Correct 16 ms 46436 KB Output is correct
52 Correct 18 ms 46436 KB Output is correct
53 Correct 17 ms 46436 KB Output is correct
54 Correct 22 ms 46436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14584 KB Output is correct
2 Correct 13 ms 14584 KB Output is correct
3 Correct 13 ms 14584 KB Output is correct
4 Correct 12 ms 14584 KB Output is correct
5 Correct 13 ms 14584 KB Output is correct
6 Correct 13 ms 14636 KB Output is correct
7 Correct 13 ms 14648 KB Output is correct
8 Correct 13 ms 14700 KB Output is correct
9 Correct 13 ms 14800 KB Output is correct
10 Correct 14 ms 14800 KB Output is correct
11 Correct 12 ms 14800 KB Output is correct
12 Correct 14 ms 14800 KB Output is correct
13 Correct 15 ms 14800 KB Output is correct
14 Correct 12 ms 14800 KB Output is correct
15 Correct 15 ms 14800 KB Output is correct
16 Correct 13 ms 14800 KB Output is correct
17 Correct 13 ms 14800 KB Output is correct
18 Correct 13 ms 14800 KB Output is correct
19 Correct 13 ms 14800 KB Output is correct
20 Correct 15 ms 14800 KB Output is correct
21 Correct 13 ms 14800 KB Output is correct
22 Correct 13 ms 14800 KB Output is correct
23 Correct 13 ms 14800 KB Output is correct
24 Correct 13 ms 14800 KB Output is correct
25 Correct 14 ms 14800 KB Output is correct
26 Correct 14 ms 14800 KB Output is correct
27 Correct 14 ms 14824 KB Output is correct
28 Correct 13 ms 14824 KB Output is correct
29 Correct 14 ms 14952 KB Output is correct
30 Correct 14 ms 14952 KB Output is correct
31 Correct 14 ms 15044 KB Output is correct
32 Correct 17 ms 15188 KB Output is correct
33 Correct 17 ms 15340 KB Output is correct
34 Correct 18 ms 15756 KB Output is correct
35 Correct 21 ms 16440 KB Output is correct
36 Correct 22 ms 16504 KB Output is correct
37 Correct 22 ms 16504 KB Output is correct
38 Correct 33 ms 17892 KB Output is correct
39 Correct 23 ms 17892 KB Output is correct
40 Correct 16 ms 17892 KB Output is correct
41 Correct 18 ms 17892 KB Output is correct
42 Correct 16 ms 17892 KB Output is correct
43 Correct 151 ms 46436 KB Output is correct
44 Correct 128 ms 46436 KB Output is correct
45 Correct 126 ms 46436 KB Output is correct
46 Correct 17 ms 46436 KB Output is correct
47 Correct 16 ms 46436 KB Output is correct
48 Correct 16 ms 46436 KB Output is correct
49 Correct 21 ms 46436 KB Output is correct
50 Correct 17 ms 46436 KB Output is correct
51 Correct 16 ms 46436 KB Output is correct
52 Correct 18 ms 46436 KB Output is correct
53 Correct 17 ms 46436 KB Output is correct
54 Correct 22 ms 46436 KB Output is correct
55 Correct 58 ms 46436 KB Output is correct
56 Correct 329 ms 69904 KB Output is correct
57 Correct 672 ms 122584 KB Output is correct
58 Correct 767 ms 141308 KB Output is correct
59 Correct 1695 ms 295712 KB Output is correct
60 Correct 1694 ms 295712 KB Output is correct
61 Execution timed out 2094 ms 360868 KB Time limit exceeded
62 Halted 0 ms 0 KB -