Submission #56314

# Submission time Handle Problem Language Result Execution time Memory
56314 2018-07-11T04:48:05 Z 윤교준(#1600) Construction of Highway (JOI18_construction) C++11
16 / 100
1000 ms 14224 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 100005;

int prt[MAXN];

int A[MAXN], B[MAXN], C[MAXN];

int N;

int main() {
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 1; i <= N; i++) cin >> C[i];
	for(int i = 1; i < N; i++) cin >> A[i] >> B[i];

	for(int qi = 1, a, b; qi < N; qi++) {
		a = A[qi]; b = B[qi];

		vector<int> V;
		for(int i = a; 1 < i; i = prt[i]) V.pb(i);
		V.pb(1);
		revv(V);

		vector<pii> T;
		for(int v : V) {
			if(T.empty() || T.back().first != C[v]) T.eb(C[v], 1);
			else T.back().second++;
		}

		ll ret = 0;
		for(int i = 0; i < sz(T); i++) for(int j = i+1; j < sz(T); j++)
			if(T[i].first > T[j].first) ret += ll(T[i].second) * T[j].second;

		for(int v : V) C[v] = C[b];

		prt[b] = a;

		printf("%lld\n", ret);
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 424 KB Output is correct
4 Correct 2 ms 428 KB Output is correct
5 Correct 4 ms 536 KB Output is correct
6 Correct 3 ms 536 KB Output is correct
7 Correct 3 ms 536 KB Output is correct
8 Correct 5 ms 676 KB Output is correct
9 Correct 4 ms 676 KB Output is correct
10 Correct 5 ms 676 KB Output is correct
11 Correct 4 ms 676 KB Output is correct
12 Correct 4 ms 676 KB Output is correct
13 Correct 4 ms 676 KB Output is correct
14 Correct 3 ms 684 KB Output is correct
15 Correct 3 ms 728 KB Output is correct
16 Correct 3 ms 728 KB Output is correct
17 Correct 3 ms 728 KB Output is correct
18 Correct 3 ms 728 KB Output is correct
19 Correct 4 ms 728 KB Output is correct
20 Correct 4 ms 728 KB Output is correct
21 Correct 3 ms 728 KB Output is correct
22 Correct 3 ms 728 KB Output is correct
23 Correct 4 ms 856 KB Output is correct
24 Correct 3 ms 856 KB Output is correct
25 Correct 3 ms 856 KB Output is correct
26 Correct 4 ms 856 KB Output is correct
27 Correct 4 ms 856 KB Output is correct
28 Correct 4 ms 856 KB Output is correct
29 Correct 9 ms 856 KB Output is correct
30 Correct 3 ms 856 KB Output is correct
31 Correct 3 ms 856 KB Output is correct
32 Correct 3 ms 856 KB Output is correct
33 Correct 3 ms 856 KB Output is correct
34 Correct 3 ms 856 KB Output is correct
35 Correct 4 ms 856 KB Output is correct
36 Correct 3 ms 856 KB Output is correct
37 Correct 3 ms 856 KB Output is correct
38 Correct 3 ms 856 KB Output is correct
39 Correct 3 ms 856 KB Output is correct
40 Correct 3 ms 856 KB Output is correct
41 Correct 5 ms 856 KB Output is correct
42 Correct 3 ms 856 KB Output is correct
43 Correct 3 ms 856 KB Output is correct
44 Correct 2 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 424 KB Output is correct
4 Correct 2 ms 428 KB Output is correct
5 Correct 4 ms 536 KB Output is correct
6 Correct 3 ms 536 KB Output is correct
7 Correct 3 ms 536 KB Output is correct
8 Correct 5 ms 676 KB Output is correct
9 Correct 4 ms 676 KB Output is correct
10 Correct 5 ms 676 KB Output is correct
11 Correct 4 ms 676 KB Output is correct
12 Correct 4 ms 676 KB Output is correct
13 Correct 4 ms 676 KB Output is correct
14 Correct 3 ms 684 KB Output is correct
15 Correct 3 ms 728 KB Output is correct
16 Correct 3 ms 728 KB Output is correct
17 Correct 3 ms 728 KB Output is correct
18 Correct 3 ms 728 KB Output is correct
19 Correct 4 ms 728 KB Output is correct
20 Correct 4 ms 728 KB Output is correct
21 Correct 3 ms 728 KB Output is correct
22 Correct 3 ms 728 KB Output is correct
23 Correct 4 ms 856 KB Output is correct
24 Correct 3 ms 856 KB Output is correct
25 Correct 3 ms 856 KB Output is correct
26 Correct 4 ms 856 KB Output is correct
27 Correct 4 ms 856 KB Output is correct
28 Correct 4 ms 856 KB Output is correct
29 Correct 9 ms 856 KB Output is correct
30 Correct 3 ms 856 KB Output is correct
31 Correct 3 ms 856 KB Output is correct
32 Correct 3 ms 856 KB Output is correct
33 Correct 3 ms 856 KB Output is correct
34 Correct 3 ms 856 KB Output is correct
35 Correct 4 ms 856 KB Output is correct
36 Correct 3 ms 856 KB Output is correct
37 Correct 3 ms 856 KB Output is correct
38 Correct 3 ms 856 KB Output is correct
39 Correct 3 ms 856 KB Output is correct
40 Correct 3 ms 856 KB Output is correct
41 Correct 5 ms 856 KB Output is correct
42 Correct 3 ms 856 KB Output is correct
43 Correct 3 ms 856 KB Output is correct
44 Correct 2 ms 856 KB Output is correct
45 Correct 4 ms 856 KB Output is correct
46 Correct 7 ms 856 KB Output is correct
47 Correct 7 ms 856 KB Output is correct
48 Correct 7 ms 860 KB Output is correct
49 Correct 66 ms 912 KB Output is correct
50 Correct 77 ms 1148 KB Output is correct
51 Correct 68 ms 1208 KB Output is correct
52 Correct 45 ms 1248 KB Output is correct
53 Correct 79 ms 1404 KB Output is correct
54 Correct 50 ms 1428 KB Output is correct
55 Correct 48 ms 1520 KB Output is correct
56 Correct 39 ms 1552 KB Output is correct
57 Correct 9 ms 1628 KB Output is correct
58 Correct 10 ms 1656 KB Output is correct
59 Correct 10 ms 1808 KB Output is correct
60 Correct 15 ms 1832 KB Output is correct
61 Correct 36 ms 1912 KB Output is correct
62 Correct 42 ms 1988 KB Output is correct
63 Correct 41 ms 2192 KB Output is correct
64 Correct 8 ms 2268 KB Output is correct
65 Correct 7 ms 2268 KB Output is correct
66 Correct 10 ms 2268 KB Output is correct
67 Correct 9 ms 2288 KB Output is correct
68 Correct 66 ms 2472 KB Output is correct
69 Correct 38 ms 2472 KB Output is correct
70 Correct 43 ms 2476 KB Output is correct
71 Correct 35 ms 2496 KB Output is correct
72 Correct 12 ms 2544 KB Output is correct
73 Correct 8 ms 2600 KB Output is correct
74 Correct 43 ms 2776 KB Output is correct
75 Correct 25 ms 2776 KB Output is correct
76 Correct 21 ms 2800 KB Output is correct
77 Correct 15 ms 2824 KB Output is correct
78 Correct 26 ms 2976 KB Output is correct
79 Correct 19 ms 3084 KB Output is correct
80 Correct 15 ms 3084 KB Output is correct
81 Correct 24 ms 3084 KB Output is correct
82 Correct 20 ms 3096 KB Output is correct
83 Correct 17 ms 3244 KB Output is correct
84 Correct 25 ms 3244 KB Output is correct
85 Correct 25 ms 3244 KB Output is correct
86 Correct 16 ms 3344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 424 KB Output is correct
4 Correct 2 ms 428 KB Output is correct
5 Correct 4 ms 536 KB Output is correct
6 Correct 3 ms 536 KB Output is correct
7 Correct 3 ms 536 KB Output is correct
8 Correct 5 ms 676 KB Output is correct
9 Correct 4 ms 676 KB Output is correct
10 Correct 5 ms 676 KB Output is correct
11 Correct 4 ms 676 KB Output is correct
12 Correct 4 ms 676 KB Output is correct
13 Correct 4 ms 676 KB Output is correct
14 Correct 3 ms 684 KB Output is correct
15 Correct 3 ms 728 KB Output is correct
16 Correct 3 ms 728 KB Output is correct
17 Correct 3 ms 728 KB Output is correct
18 Correct 3 ms 728 KB Output is correct
19 Correct 4 ms 728 KB Output is correct
20 Correct 4 ms 728 KB Output is correct
21 Correct 3 ms 728 KB Output is correct
22 Correct 3 ms 728 KB Output is correct
23 Correct 4 ms 856 KB Output is correct
24 Correct 3 ms 856 KB Output is correct
25 Correct 3 ms 856 KB Output is correct
26 Correct 4 ms 856 KB Output is correct
27 Correct 4 ms 856 KB Output is correct
28 Correct 4 ms 856 KB Output is correct
29 Correct 9 ms 856 KB Output is correct
30 Correct 3 ms 856 KB Output is correct
31 Correct 3 ms 856 KB Output is correct
32 Correct 3 ms 856 KB Output is correct
33 Correct 3 ms 856 KB Output is correct
34 Correct 3 ms 856 KB Output is correct
35 Correct 4 ms 856 KB Output is correct
36 Correct 3 ms 856 KB Output is correct
37 Correct 3 ms 856 KB Output is correct
38 Correct 3 ms 856 KB Output is correct
39 Correct 3 ms 856 KB Output is correct
40 Correct 3 ms 856 KB Output is correct
41 Correct 5 ms 856 KB Output is correct
42 Correct 3 ms 856 KB Output is correct
43 Correct 3 ms 856 KB Output is correct
44 Correct 2 ms 856 KB Output is correct
45 Correct 4 ms 856 KB Output is correct
46 Correct 7 ms 856 KB Output is correct
47 Correct 7 ms 856 KB Output is correct
48 Correct 7 ms 860 KB Output is correct
49 Correct 66 ms 912 KB Output is correct
50 Correct 77 ms 1148 KB Output is correct
51 Correct 68 ms 1208 KB Output is correct
52 Correct 45 ms 1248 KB Output is correct
53 Correct 79 ms 1404 KB Output is correct
54 Correct 50 ms 1428 KB Output is correct
55 Correct 48 ms 1520 KB Output is correct
56 Correct 39 ms 1552 KB Output is correct
57 Correct 9 ms 1628 KB Output is correct
58 Correct 10 ms 1656 KB Output is correct
59 Correct 10 ms 1808 KB Output is correct
60 Correct 15 ms 1832 KB Output is correct
61 Correct 36 ms 1912 KB Output is correct
62 Correct 42 ms 1988 KB Output is correct
63 Correct 41 ms 2192 KB Output is correct
64 Correct 8 ms 2268 KB Output is correct
65 Correct 7 ms 2268 KB Output is correct
66 Correct 10 ms 2268 KB Output is correct
67 Correct 9 ms 2288 KB Output is correct
68 Correct 66 ms 2472 KB Output is correct
69 Correct 38 ms 2472 KB Output is correct
70 Correct 43 ms 2476 KB Output is correct
71 Correct 35 ms 2496 KB Output is correct
72 Correct 12 ms 2544 KB Output is correct
73 Correct 8 ms 2600 KB Output is correct
74 Correct 43 ms 2776 KB Output is correct
75 Correct 25 ms 2776 KB Output is correct
76 Correct 21 ms 2800 KB Output is correct
77 Correct 15 ms 2824 KB Output is correct
78 Correct 26 ms 2976 KB Output is correct
79 Correct 19 ms 3084 KB Output is correct
80 Correct 15 ms 3084 KB Output is correct
81 Correct 24 ms 3084 KB Output is correct
82 Correct 20 ms 3096 KB Output is correct
83 Correct 17 ms 3244 KB Output is correct
84 Correct 25 ms 3244 KB Output is correct
85 Correct 25 ms 3244 KB Output is correct
86 Correct 16 ms 3344 KB Output is correct
87 Correct 13 ms 3624 KB Output is correct
88 Correct 38 ms 4584 KB Output is correct
89 Correct 236 ms 7908 KB Output is correct
90 Correct 180 ms 10276 KB Output is correct
91 Correct 137 ms 12260 KB Output is correct
92 Execution timed out 1071 ms 14224 KB Time limit exceeded
93 Halted 0 ms 0 KB -