# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
131918 | 2019-07-18T04:07:34 Z | 임유진(#3191) | Construction of Highway (JOI18_construction) | C++14 | 153 ms | 668 KB |
#include <bits/stdc++.h> using namespace std; #define MAXN 4005 #define rb(x) ((x) & (-(x))) int C[MAXN], A[MAXN], B[MAXN]; int L[MAXN], par[MAXN]; int cs[MAXN]; int bit[MAXN]; void updbit(int x) { for(; x < MAXN; x += rb(x)) bit[x]++; } int gbit(int x) { int ans = 0; for(; x > 0; x -= rb(x)) ans += bit[x]; return ans; } int main() { int N; scanf("%d", &N); for(int i = 1; i <= N; i++) scanf("%d", C + i); for(int i = 0; i < N - 1; i++) scanf("%d%d", A + i, B + i); for(int i = 1; i <= N; i++) cs[i - 1] = C[i]; sort(cs, cs + N); for(int i = 1; i <= N; i++) C[i] = lower_bound(cs, cs + N, C[i]) - cs + 1; L[1] = C[1]; for(int i = 0; i < N - 1; i++) { for(int j = 1; j < MAXN; j++) bit[j] = 0; int ans = 0; L[B[i]] = C[B[i]]; par[B[i]] = A[i]; for(int t = A[i]; t != 0; t = par[t]) { ans += gbit(L[t] - 1); updbit(L[t]); L[t] = C[B[i]]; } printf("%d\n", ans); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 4 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 6 ms | 376 KB | Output is correct |
10 | Correct | 6 ms | 376 KB | Output is correct |
11 | Correct | 4 ms | 376 KB | Output is correct |
12 | Correct | 4 ms | 376 KB | Output is correct |
13 | Correct | 4 ms | 376 KB | Output is correct |
14 | Correct | 4 ms | 376 KB | Output is correct |
15 | Correct | 3 ms | 376 KB | Output is correct |
16 | Correct | 3 ms | 400 KB | Output is correct |
17 | Correct | 3 ms | 376 KB | Output is correct |
18 | Correct | 3 ms | 372 KB | Output is correct |
19 | Correct | 4 ms | 376 KB | Output is correct |
20 | Correct | 4 ms | 376 KB | Output is correct |
21 | Correct | 4 ms | 404 KB | Output is correct |
22 | Correct | 3 ms | 376 KB | Output is correct |
23 | Correct | 3 ms | 376 KB | Output is correct |
24 | Correct | 3 ms | 400 KB | Output is correct |
25 | Correct | 3 ms | 376 KB | Output is correct |
26 | Correct | 6 ms | 376 KB | Output is correct |
27 | Correct | 5 ms | 548 KB | Output is correct |
28 | Correct | 4 ms | 376 KB | Output is correct |
29 | Correct | 4 ms | 376 KB | Output is correct |
30 | Correct | 3 ms | 376 KB | Output is correct |
31 | Correct | 3 ms | 376 KB | Output is correct |
32 | Correct | 4 ms | 376 KB | Output is correct |
33 | Correct | 4 ms | 376 KB | Output is correct |
34 | Correct | 4 ms | 376 KB | Output is correct |
35 | Correct | 4 ms | 376 KB | Output is correct |
36 | Correct | 4 ms | 376 KB | Output is correct |
37 | Correct | 4 ms | 376 KB | Output is correct |
38 | Correct | 4 ms | 376 KB | Output is correct |
39 | Correct | 4 ms | 376 KB | Output is correct |
40 | Correct | 4 ms | 376 KB | Output is correct |
41 | Correct | 4 ms | 376 KB | Output is correct |
42 | Correct | 4 ms | 504 KB | Output is correct |
43 | Correct | 4 ms | 376 KB | Output is correct |
44 | Correct | 3 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 4 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 6 ms | 376 KB | Output is correct |
10 | Correct | 6 ms | 376 KB | Output is correct |
11 | Correct | 4 ms | 376 KB | Output is correct |
12 | Correct | 4 ms | 376 KB | Output is correct |
13 | Correct | 4 ms | 376 KB | Output is correct |
14 | Correct | 4 ms | 376 KB | Output is correct |
15 | Correct | 3 ms | 376 KB | Output is correct |
16 | Correct | 3 ms | 400 KB | Output is correct |
17 | Correct | 3 ms | 376 KB | Output is correct |
18 | Correct | 3 ms | 372 KB | Output is correct |
19 | Correct | 4 ms | 376 KB | Output is correct |
20 | Correct | 4 ms | 376 KB | Output is correct |
21 | Correct | 4 ms | 404 KB | Output is correct |
22 | Correct | 3 ms | 376 KB | Output is correct |
23 | Correct | 3 ms | 376 KB | Output is correct |
24 | Correct | 3 ms | 400 KB | Output is correct |
25 | Correct | 3 ms | 376 KB | Output is correct |
26 | Correct | 6 ms | 376 KB | Output is correct |
27 | Correct | 5 ms | 548 KB | Output is correct |
28 | Correct | 4 ms | 376 KB | Output is correct |
29 | Correct | 4 ms | 376 KB | Output is correct |
30 | Correct | 3 ms | 376 KB | Output is correct |
31 | Correct | 3 ms | 376 KB | Output is correct |
32 | Correct | 4 ms | 376 KB | Output is correct |
33 | Correct | 4 ms | 376 KB | Output is correct |
34 | Correct | 4 ms | 376 KB | Output is correct |
35 | Correct | 4 ms | 376 KB | Output is correct |
36 | Correct | 4 ms | 376 KB | Output is correct |
37 | Correct | 4 ms | 376 KB | Output is correct |
38 | Correct | 4 ms | 376 KB | Output is correct |
39 | Correct | 4 ms | 376 KB | Output is correct |
40 | Correct | 4 ms | 376 KB | Output is correct |
41 | Correct | 4 ms | 376 KB | Output is correct |
42 | Correct | 4 ms | 504 KB | Output is correct |
43 | Correct | 4 ms | 376 KB | Output is correct |
44 | Correct | 3 ms | 376 KB | Output is correct |
45 | Correct | 5 ms | 376 KB | Output is correct |
46 | Correct | 13 ms | 504 KB | Output is correct |
47 | Correct | 13 ms | 504 KB | Output is correct |
48 | Correct | 13 ms | 504 KB | Output is correct |
49 | Correct | 152 ms | 632 KB | Output is correct |
50 | Correct | 153 ms | 604 KB | Output is correct |
51 | Correct | 151 ms | 552 KB | Output is correct |
52 | Correct | 86 ms | 504 KB | Output is correct |
53 | Correct | 84 ms | 552 KB | Output is correct |
54 | Correct | 83 ms | 532 KB | Output is correct |
55 | Correct | 84 ms | 504 KB | Output is correct |
56 | Correct | 83 ms | 504 KB | Output is correct |
57 | Correct | 13 ms | 504 KB | Output is correct |
58 | Correct | 13 ms | 504 KB | Output is correct |
59 | Correct | 13 ms | 504 KB | Output is correct |
60 | Correct | 13 ms | 504 KB | Output is correct |
61 | Correct | 83 ms | 504 KB | Output is correct |
62 | Correct | 83 ms | 504 KB | Output is correct |
63 | Correct | 84 ms | 604 KB | Output is correct |
64 | Correct | 15 ms | 504 KB | Output is correct |
65 | Correct | 13 ms | 504 KB | Output is correct |
66 | Correct | 12 ms | 504 KB | Output is correct |
67 | Correct | 13 ms | 632 KB | Output is correct |
68 | Correct | 153 ms | 504 KB | Output is correct |
69 | Correct | 83 ms | 504 KB | Output is correct |
70 | Correct | 84 ms | 504 KB | Output is correct |
71 | Correct | 83 ms | 536 KB | Output is correct |
72 | Correct | 14 ms | 504 KB | Output is correct |
73 | Correct | 13 ms | 504 KB | Output is correct |
74 | Correct | 86 ms | 508 KB | Output is correct |
75 | Correct | 52 ms | 668 KB | Output is correct |
76 | Correct | 37 ms | 504 KB | Output is correct |
77 | Correct | 31 ms | 504 KB | Output is correct |
78 | Correct | 48 ms | 504 KB | Output is correct |
79 | Correct | 37 ms | 504 KB | Output is correct |
80 | Correct | 31 ms | 504 KB | Output is correct |
81 | Correct | 49 ms | 504 KB | Output is correct |
82 | Correct | 37 ms | 508 KB | Output is correct |
83 | Correct | 33 ms | 532 KB | Output is correct |
84 | Correct | 48 ms | 504 KB | Output is correct |
85 | Correct | 38 ms | 516 KB | Output is correct |
86 | Correct | 31 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 4 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 6 ms | 376 KB | Output is correct |
10 | Correct | 6 ms | 376 KB | Output is correct |
11 | Correct | 4 ms | 376 KB | Output is correct |
12 | Correct | 4 ms | 376 KB | Output is correct |
13 | Correct | 4 ms | 376 KB | Output is correct |
14 | Correct | 4 ms | 376 KB | Output is correct |
15 | Correct | 3 ms | 376 KB | Output is correct |
16 | Correct | 3 ms | 400 KB | Output is correct |
17 | Correct | 3 ms | 376 KB | Output is correct |
18 | Correct | 3 ms | 372 KB | Output is correct |
19 | Correct | 4 ms | 376 KB | Output is correct |
20 | Correct | 4 ms | 376 KB | Output is correct |
21 | Correct | 4 ms | 404 KB | Output is correct |
22 | Correct | 3 ms | 376 KB | Output is correct |
23 | Correct | 3 ms | 376 KB | Output is correct |
24 | Correct | 3 ms | 400 KB | Output is correct |
25 | Correct | 3 ms | 376 KB | Output is correct |
26 | Correct | 6 ms | 376 KB | Output is correct |
27 | Correct | 5 ms | 548 KB | Output is correct |
28 | Correct | 4 ms | 376 KB | Output is correct |
29 | Correct | 4 ms | 376 KB | Output is correct |
30 | Correct | 3 ms | 376 KB | Output is correct |
31 | Correct | 3 ms | 376 KB | Output is correct |
32 | Correct | 4 ms | 376 KB | Output is correct |
33 | Correct | 4 ms | 376 KB | Output is correct |
34 | Correct | 4 ms | 376 KB | Output is correct |
35 | Correct | 4 ms | 376 KB | Output is correct |
36 | Correct | 4 ms | 376 KB | Output is correct |
37 | Correct | 4 ms | 376 KB | Output is correct |
38 | Correct | 4 ms | 376 KB | Output is correct |
39 | Correct | 4 ms | 376 KB | Output is correct |
40 | Correct | 4 ms | 376 KB | Output is correct |
41 | Correct | 4 ms | 376 KB | Output is correct |
42 | Correct | 4 ms | 504 KB | Output is correct |
43 | Correct | 4 ms | 376 KB | Output is correct |
44 | Correct | 3 ms | 376 KB | Output is correct |
45 | Correct | 5 ms | 376 KB | Output is correct |
46 | Correct | 13 ms | 504 KB | Output is correct |
47 | Correct | 13 ms | 504 KB | Output is correct |
48 | Correct | 13 ms | 504 KB | Output is correct |
49 | Correct | 152 ms | 632 KB | Output is correct |
50 | Correct | 153 ms | 604 KB | Output is correct |
51 | Correct | 151 ms | 552 KB | Output is correct |
52 | Correct | 86 ms | 504 KB | Output is correct |
53 | Correct | 84 ms | 552 KB | Output is correct |
54 | Correct | 83 ms | 532 KB | Output is correct |
55 | Correct | 84 ms | 504 KB | Output is correct |
56 | Correct | 83 ms | 504 KB | Output is correct |
57 | Correct | 13 ms | 504 KB | Output is correct |
58 | Correct | 13 ms | 504 KB | Output is correct |
59 | Correct | 13 ms | 504 KB | Output is correct |
60 | Correct | 13 ms | 504 KB | Output is correct |
61 | Correct | 83 ms | 504 KB | Output is correct |
62 | Correct | 83 ms | 504 KB | Output is correct |
63 | Correct | 84 ms | 604 KB | Output is correct |
64 | Correct | 15 ms | 504 KB | Output is correct |
65 | Correct | 13 ms | 504 KB | Output is correct |
66 | Correct | 12 ms | 504 KB | Output is correct |
67 | Correct | 13 ms | 632 KB | Output is correct |
68 | Correct | 153 ms | 504 KB | Output is correct |
69 | Correct | 83 ms | 504 KB | Output is correct |
70 | Correct | 84 ms | 504 KB | Output is correct |
71 | Correct | 83 ms | 536 KB | Output is correct |
72 | Correct | 14 ms | 504 KB | Output is correct |
73 | Correct | 13 ms | 504 KB | Output is correct |
74 | Correct | 86 ms | 508 KB | Output is correct |
75 | Correct | 52 ms | 668 KB | Output is correct |
76 | Correct | 37 ms | 504 KB | Output is correct |
77 | Correct | 31 ms | 504 KB | Output is correct |
78 | Correct | 48 ms | 504 KB | Output is correct |
79 | Correct | 37 ms | 504 KB | Output is correct |
80 | Correct | 31 ms | 504 KB | Output is correct |
81 | Correct | 49 ms | 504 KB | Output is correct |
82 | Correct | 37 ms | 508 KB | Output is correct |
83 | Correct | 33 ms | 532 KB | Output is correct |
84 | Correct | 48 ms | 504 KB | Output is correct |
85 | Correct | 38 ms | 516 KB | Output is correct |
86 | Correct | 31 ms | 504 KB | Output is correct |
87 | Execution timed out | 4 ms | 504 KB | Time limit exceeded (wall clock) |
88 | Halted | 0 ms | 0 KB | - |