#include <stdio.h>
#include <string.h>
#include <algorithm>
int a[3][200001];
long long m1[4][524300];
int m2[4][524300];
void f(int h, int l, int r, int le, int re)
{
int q = le*2 + re;
if(m1[q][h])
return;
if(l==r)
{
m1[q][h] = a[le+re][l];
m2[q][h] = 0;
return;
}
if(l+1 == r)
{
int t1 = a[le+1][l] + a[re][r];
int t2 = a[le][l] + a[re+1][r];
if(t1 >= t2)
{
m1[q][h] = t1;
m2[q][h] = -1;
}
else
{
m1[q][h] = t2;
m2[q][h] = -2;
}
return;
}
int x = (l+r)/2;
f(2*h, l, x-1, le, 0);
f(2*h, l, x-1, le, 1);
f(2*h+1, x+1, r, 0, re);
f(2*h+1, x+1, r, 1, re);
long long tl0 = m1[2*le][2*h];
long long tl1 = m1[2*le+1][2*h];
long long tr0 = m1[re][2*h+1];
long long tr1 = m1[2+re][2*h+1];
long long p1 = a[2][x] + tl0 + tr0;
long long p2 = a[1][x] + tl1 + tr0;
long long p3 = a[0][x] + tl1 + tr1;
long long p4 = a[1][x] + tl0 + tr1;
long long p5 = a[0][x] + tl1 + tr1;
long long pm = std::max({p1, p2, p3, p4, p5});
m1[q][h] = pm;
if(p1 == pm)
m2[q][h] = 1;
else if(p2 == pm)
m2[q][h] = 2;
else if(p3 == pm)
m2[q][h] = 3;
else if(p4 == pm)
m2[q][h] = 4;
else if(p5 == pm)
m2[q][h] = 5;
}
void g(int h, int l, int r, int le, int re)
{
int q = le*2 + re;
int x = (l+r)/2;
switch(m2[q][h])
{
case 0:
printf("%d ", l);
break;
case -1:
printf("%d %d ", l, r);
break;
case -2:
printf("%d %d ", r, l);
break;
case 1:
printf("%d ", x);
g(2*h, l, x-1, le, 0);
g(2*h+1, x+1, r, 0, re);
break;
case 2:
g(2*h, l, x-1, le, 1);
printf("%d ", x);
g(2*h+1, x+1, r, 0, re);
break;
case 3:
g(2*h, l, x-1, le, 1);
g(2*h+1, x+1, r, 1, re);
printf("%d ", x);
break;
case 4:
g(2*h+1, x+1, r, 1, re);
printf("%d ", x);
g(2*h, l, x-1, le, 0);
break;
case 5:
g(2*h+1, x+1, r, 1, re);
g(2*h, l, x-1, le, 1);
printf("%d ", x);
break;
}
}
int main()
{
int n, i;
scanf("%d", &n);
for(i = 1; i<=n; i++)
scanf("%d%d%d", &a[2][i], &a[1][i], &a[0][i]);
f(1, 1, n, 1, 1);
printf("%lld\n", m1[3][1]);
g(1, 1, n, 1, 1);
return 0;
}
Compilation message
space.cpp: In function 'int main()':
space.cpp:123:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
space.cpp:125:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &a[2][i], &a[1][i], &a[0][i]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
28036 KB |
Output is correct |
2 |
Correct |
0 ms |
28036 KB |
Output is correct |
3 |
Correct |
0 ms |
28036 KB |
Output is correct |
4 |
Correct |
0 ms |
28036 KB |
Output is correct |
5 |
Correct |
0 ms |
28036 KB |
Output is correct |
6 |
Correct |
0 ms |
28036 KB |
Output is correct |
7 |
Correct |
0 ms |
28036 KB |
Output is correct |
8 |
Correct |
0 ms |
28036 KB |
Output is correct |
9 |
Correct |
0 ms |
28036 KB |
Output is correct |
10 |
Correct |
0 ms |
28036 KB |
Output is correct |
11 |
Correct |
0 ms |
28036 KB |
Output is correct |
12 |
Correct |
0 ms |
28036 KB |
Output is correct |
13 |
Correct |
0 ms |
28036 KB |
Output is correct |
14 |
Correct |
0 ms |
28036 KB |
Output is correct |
15 |
Correct |
0 ms |
28036 KB |
Output is correct |
16 |
Correct |
0 ms |
28036 KB |
Output is correct |
17 |
Correct |
0 ms |
28036 KB |
Output is correct |
18 |
Correct |
0 ms |
28036 KB |
Output is correct |
19 |
Correct |
0 ms |
28036 KB |
Output is correct |
20 |
Correct |
0 ms |
28036 KB |
Output is correct |
21 |
Correct |
0 ms |
28036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
28036 KB |
Output is correct |
2 |
Correct |
0 ms |
28036 KB |
Output is correct |
3 |
Correct |
0 ms |
28036 KB |
Output is correct |
4 |
Correct |
0 ms |
28036 KB |
Output is correct |
5 |
Correct |
0 ms |
28036 KB |
Output is correct |
6 |
Correct |
0 ms |
28036 KB |
Output is correct |
7 |
Correct |
0 ms |
28036 KB |
Output is correct |
8 |
Correct |
0 ms |
28036 KB |
Output is correct |
9 |
Correct |
0 ms |
28036 KB |
Output is correct |
10 |
Correct |
0 ms |
28036 KB |
Output is correct |
11 |
Correct |
0 ms |
28036 KB |
Output is correct |
12 |
Correct |
0 ms |
28036 KB |
Output is correct |
13 |
Correct |
0 ms |
28036 KB |
Output is correct |
14 |
Correct |
0 ms |
28036 KB |
Output is correct |
15 |
Correct |
0 ms |
28036 KB |
Output is correct |
16 |
Correct |
0 ms |
28036 KB |
Output is correct |
17 |
Correct |
0 ms |
28036 KB |
Output is correct |
18 |
Correct |
0 ms |
28036 KB |
Output is correct |
19 |
Correct |
0 ms |
28036 KB |
Output is correct |
20 |
Correct |
0 ms |
28036 KB |
Output is correct |
21 |
Correct |
0 ms |
28036 KB |
Output is correct |
22 |
Correct |
0 ms |
28036 KB |
Output is correct |
23 |
Correct |
0 ms |
28036 KB |
Output is correct |
24 |
Correct |
0 ms |
28036 KB |
Output is correct |
25 |
Correct |
0 ms |
28036 KB |
Output is correct |
26 |
Correct |
0 ms |
28036 KB |
Output is correct |
27 |
Correct |
0 ms |
28036 KB |
Output is correct |
28 |
Correct |
0 ms |
28036 KB |
Output is correct |
29 |
Correct |
0 ms |
28036 KB |
Output is correct |
30 |
Correct |
0 ms |
28036 KB |
Output is correct |
31 |
Correct |
0 ms |
28036 KB |
Output is correct |
32 |
Correct |
0 ms |
28036 KB |
Output is correct |
33 |
Correct |
0 ms |
28036 KB |
Output is correct |
34 |
Correct |
0 ms |
28036 KB |
Output is correct |
35 |
Correct |
0 ms |
28036 KB |
Output is correct |
36 |
Correct |
0 ms |
28036 KB |
Output is correct |
37 |
Correct |
0 ms |
28036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
28036 KB |
Output is correct |
2 |
Correct |
0 ms |
28036 KB |
Output is correct |
3 |
Correct |
0 ms |
28036 KB |
Output is correct |
4 |
Correct |
0 ms |
28036 KB |
Output is correct |
5 |
Correct |
0 ms |
28036 KB |
Output is correct |
6 |
Correct |
0 ms |
28036 KB |
Output is correct |
7 |
Correct |
0 ms |
28036 KB |
Output is correct |
8 |
Correct |
0 ms |
28036 KB |
Output is correct |
9 |
Correct |
0 ms |
28036 KB |
Output is correct |
10 |
Correct |
0 ms |
28036 KB |
Output is correct |
11 |
Correct |
0 ms |
28036 KB |
Output is correct |
12 |
Correct |
0 ms |
28036 KB |
Output is correct |
13 |
Correct |
0 ms |
28036 KB |
Output is correct |
14 |
Correct |
0 ms |
28036 KB |
Output is correct |
15 |
Correct |
0 ms |
28036 KB |
Output is correct |
16 |
Correct |
0 ms |
28036 KB |
Output is correct |
17 |
Correct |
0 ms |
28036 KB |
Output is correct |
18 |
Correct |
0 ms |
28036 KB |
Output is correct |
19 |
Correct |
0 ms |
28036 KB |
Output is correct |
20 |
Correct |
0 ms |
28036 KB |
Output is correct |
21 |
Correct |
0 ms |
28036 KB |
Output is correct |
22 |
Correct |
0 ms |
28036 KB |
Output is correct |
23 |
Correct |
0 ms |
28036 KB |
Output is correct |
24 |
Correct |
0 ms |
28036 KB |
Output is correct |
25 |
Correct |
0 ms |
28036 KB |
Output is correct |
26 |
Correct |
0 ms |
28036 KB |
Output is correct |
27 |
Correct |
0 ms |
28036 KB |
Output is correct |
28 |
Correct |
0 ms |
28036 KB |
Output is correct |
29 |
Correct |
0 ms |
28036 KB |
Output is correct |
30 |
Correct |
0 ms |
28036 KB |
Output is correct |
31 |
Correct |
0 ms |
28036 KB |
Output is correct |
32 |
Correct |
0 ms |
28036 KB |
Output is correct |
33 |
Correct |
0 ms |
28036 KB |
Output is correct |
34 |
Correct |
0 ms |
28036 KB |
Output is correct |
35 |
Correct |
0 ms |
28036 KB |
Output is correct |
36 |
Correct |
0 ms |
28036 KB |
Output is correct |
37 |
Correct |
0 ms |
28036 KB |
Output is correct |
38 |
Correct |
0 ms |
28036 KB |
Output is correct |
39 |
Correct |
0 ms |
28036 KB |
Output is correct |
40 |
Correct |
0 ms |
28036 KB |
Output is correct |
41 |
Correct |
0 ms |
28036 KB |
Output is correct |
42 |
Correct |
0 ms |
28036 KB |
Output is correct |
43 |
Correct |
0 ms |
28036 KB |
Output is correct |
44 |
Correct |
0 ms |
28036 KB |
Output is correct |
45 |
Correct |
0 ms |
28036 KB |
Output is correct |
46 |
Correct |
0 ms |
28036 KB |
Output is correct |
47 |
Correct |
0 ms |
28036 KB |
Output is correct |
48 |
Correct |
0 ms |
28036 KB |
Output is correct |
49 |
Correct |
0 ms |
28036 KB |
Output is correct |
50 |
Correct |
0 ms |
28036 KB |
Output is correct |
51 |
Correct |
0 ms |
28036 KB |
Output is correct |
52 |
Correct |
0 ms |
28036 KB |
Output is correct |
53 |
Correct |
0 ms |
28036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
28036 KB |
Output is correct |
2 |
Correct |
0 ms |
28036 KB |
Output is correct |
3 |
Correct |
0 ms |
28036 KB |
Output is correct |
4 |
Correct |
0 ms |
28036 KB |
Output is correct |
5 |
Correct |
0 ms |
28036 KB |
Output is correct |
6 |
Correct |
0 ms |
28036 KB |
Output is correct |
7 |
Correct |
0 ms |
28036 KB |
Output is correct |
8 |
Correct |
0 ms |
28036 KB |
Output is correct |
9 |
Correct |
0 ms |
28036 KB |
Output is correct |
10 |
Correct |
0 ms |
28036 KB |
Output is correct |
11 |
Correct |
0 ms |
28036 KB |
Output is correct |
12 |
Correct |
0 ms |
28036 KB |
Output is correct |
13 |
Correct |
0 ms |
28036 KB |
Output is correct |
14 |
Correct |
0 ms |
28036 KB |
Output is correct |
15 |
Correct |
0 ms |
28036 KB |
Output is correct |
16 |
Correct |
0 ms |
28036 KB |
Output is correct |
17 |
Correct |
0 ms |
28036 KB |
Output is correct |
18 |
Correct |
0 ms |
28036 KB |
Output is correct |
19 |
Correct |
0 ms |
28036 KB |
Output is correct |
20 |
Correct |
0 ms |
28036 KB |
Output is correct |
21 |
Correct |
0 ms |
28036 KB |
Output is correct |
22 |
Correct |
0 ms |
28036 KB |
Output is correct |
23 |
Correct |
0 ms |
28036 KB |
Output is correct |
24 |
Correct |
0 ms |
28036 KB |
Output is correct |
25 |
Correct |
0 ms |
28036 KB |
Output is correct |
26 |
Correct |
0 ms |
28036 KB |
Output is correct |
27 |
Correct |
0 ms |
28036 KB |
Output is correct |
28 |
Correct |
0 ms |
28036 KB |
Output is correct |
29 |
Correct |
0 ms |
28036 KB |
Output is correct |
30 |
Correct |
0 ms |
28036 KB |
Output is correct |
31 |
Correct |
0 ms |
28036 KB |
Output is correct |
32 |
Correct |
0 ms |
28036 KB |
Output is correct |
33 |
Correct |
0 ms |
28036 KB |
Output is correct |
34 |
Correct |
0 ms |
28036 KB |
Output is correct |
35 |
Correct |
0 ms |
28036 KB |
Output is correct |
36 |
Correct |
0 ms |
28036 KB |
Output is correct |
37 |
Correct |
0 ms |
28036 KB |
Output is correct |
38 |
Correct |
0 ms |
28036 KB |
Output is correct |
39 |
Correct |
0 ms |
28036 KB |
Output is correct |
40 |
Correct |
0 ms |
28036 KB |
Output is correct |
41 |
Correct |
0 ms |
28036 KB |
Output is correct |
42 |
Correct |
0 ms |
28036 KB |
Output is correct |
43 |
Correct |
0 ms |
28036 KB |
Output is correct |
44 |
Correct |
0 ms |
28036 KB |
Output is correct |
45 |
Correct |
0 ms |
28036 KB |
Output is correct |
46 |
Correct |
0 ms |
28036 KB |
Output is correct |
47 |
Correct |
0 ms |
28036 KB |
Output is correct |
48 |
Correct |
0 ms |
28036 KB |
Output is correct |
49 |
Correct |
0 ms |
28036 KB |
Output is correct |
50 |
Correct |
0 ms |
28036 KB |
Output is correct |
51 |
Correct |
0 ms |
28036 KB |
Output is correct |
52 |
Correct |
0 ms |
28036 KB |
Output is correct |
53 |
Correct |
0 ms |
28036 KB |
Output is correct |
54 |
Correct |
0 ms |
28036 KB |
Output is correct |
55 |
Correct |
3 ms |
28036 KB |
Output is correct |
56 |
Correct |
6 ms |
28036 KB |
Output is correct |
57 |
Correct |
6 ms |
28036 KB |
Output is correct |
58 |
Correct |
6 ms |
28036 KB |
Output is correct |
59 |
Correct |
3 ms |
28036 KB |
Output is correct |
60 |
Correct |
3 ms |
28036 KB |
Output is correct |
61 |
Correct |
6 ms |
28036 KB |
Output is correct |
62 |
Correct |
3 ms |
28036 KB |
Output is correct |
63 |
Correct |
0 ms |
28036 KB |
Output is correct |
64 |
Correct |
3 ms |
28036 KB |
Output is correct |
65 |
Correct |
3 ms |
28036 KB |
Output is correct |
66 |
Correct |
3 ms |
28036 KB |
Output is correct |
67 |
Correct |
3 ms |
28036 KB |
Output is correct |
68 |
Correct |
0 ms |
28036 KB |
Output is correct |
69 |
Correct |
6 ms |
28036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
28036 KB |
Output is correct |
2 |
Correct |
0 ms |
28036 KB |
Output is correct |
3 |
Correct |
0 ms |
28036 KB |
Output is correct |
4 |
Correct |
0 ms |
28036 KB |
Output is correct |
5 |
Correct |
0 ms |
28036 KB |
Output is correct |
6 |
Correct |
0 ms |
28036 KB |
Output is correct |
7 |
Correct |
0 ms |
28036 KB |
Output is correct |
8 |
Correct |
0 ms |
28036 KB |
Output is correct |
9 |
Correct |
0 ms |
28036 KB |
Output is correct |
10 |
Correct |
0 ms |
28036 KB |
Output is correct |
11 |
Correct |
0 ms |
28036 KB |
Output is correct |
12 |
Correct |
0 ms |
28036 KB |
Output is correct |
13 |
Correct |
0 ms |
28036 KB |
Output is correct |
14 |
Correct |
0 ms |
28036 KB |
Output is correct |
15 |
Correct |
0 ms |
28036 KB |
Output is correct |
16 |
Correct |
0 ms |
28036 KB |
Output is correct |
17 |
Correct |
0 ms |
28036 KB |
Output is correct |
18 |
Correct |
0 ms |
28036 KB |
Output is correct |
19 |
Correct |
0 ms |
28036 KB |
Output is correct |
20 |
Correct |
0 ms |
28036 KB |
Output is correct |
21 |
Correct |
0 ms |
28036 KB |
Output is correct |
22 |
Correct |
0 ms |
28036 KB |
Output is correct |
23 |
Correct |
0 ms |
28036 KB |
Output is correct |
24 |
Correct |
0 ms |
28036 KB |
Output is correct |
25 |
Correct |
0 ms |
28036 KB |
Output is correct |
26 |
Correct |
0 ms |
28036 KB |
Output is correct |
27 |
Correct |
0 ms |
28036 KB |
Output is correct |
28 |
Correct |
0 ms |
28036 KB |
Output is correct |
29 |
Correct |
0 ms |
28036 KB |
Output is correct |
30 |
Correct |
0 ms |
28036 KB |
Output is correct |
31 |
Correct |
0 ms |
28036 KB |
Output is correct |
32 |
Correct |
0 ms |
28036 KB |
Output is correct |
33 |
Correct |
0 ms |
28036 KB |
Output is correct |
34 |
Correct |
0 ms |
28036 KB |
Output is correct |
35 |
Correct |
0 ms |
28036 KB |
Output is correct |
36 |
Correct |
0 ms |
28036 KB |
Output is correct |
37 |
Correct |
0 ms |
28036 KB |
Output is correct |
38 |
Correct |
0 ms |
28036 KB |
Output is correct |
39 |
Correct |
0 ms |
28036 KB |
Output is correct |
40 |
Correct |
0 ms |
28036 KB |
Output is correct |
41 |
Correct |
0 ms |
28036 KB |
Output is correct |
42 |
Correct |
0 ms |
28036 KB |
Output is correct |
43 |
Correct |
0 ms |
28036 KB |
Output is correct |
44 |
Correct |
0 ms |
28036 KB |
Output is correct |
45 |
Correct |
0 ms |
28036 KB |
Output is correct |
46 |
Correct |
0 ms |
28036 KB |
Output is correct |
47 |
Correct |
0 ms |
28036 KB |
Output is correct |
48 |
Correct |
0 ms |
28036 KB |
Output is correct |
49 |
Correct |
0 ms |
28036 KB |
Output is correct |
50 |
Correct |
0 ms |
28036 KB |
Output is correct |
51 |
Correct |
0 ms |
28036 KB |
Output is correct |
52 |
Correct |
0 ms |
28036 KB |
Output is correct |
53 |
Correct |
0 ms |
28036 KB |
Output is correct |
54 |
Correct |
0 ms |
28036 KB |
Output is correct |
55 |
Correct |
3 ms |
28036 KB |
Output is correct |
56 |
Correct |
6 ms |
28036 KB |
Output is correct |
57 |
Correct |
6 ms |
28036 KB |
Output is correct |
58 |
Correct |
6 ms |
28036 KB |
Output is correct |
59 |
Correct |
3 ms |
28036 KB |
Output is correct |
60 |
Correct |
3 ms |
28036 KB |
Output is correct |
61 |
Correct |
6 ms |
28036 KB |
Output is correct |
62 |
Correct |
3 ms |
28036 KB |
Output is correct |
63 |
Correct |
0 ms |
28036 KB |
Output is correct |
64 |
Correct |
3 ms |
28036 KB |
Output is correct |
65 |
Correct |
3 ms |
28036 KB |
Output is correct |
66 |
Correct |
3 ms |
28036 KB |
Output is correct |
67 |
Correct |
3 ms |
28036 KB |
Output is correct |
68 |
Correct |
0 ms |
28036 KB |
Output is correct |
69 |
Correct |
6 ms |
28036 KB |
Output is correct |
70 |
Correct |
6 ms |
28036 KB |
Output is correct |
71 |
Correct |
136 ms |
28036 KB |
Output is correct |
72 |
Correct |
109 ms |
28036 KB |
Output is correct |
73 |
Correct |
139 ms |
28036 KB |
Output is correct |
74 |
Correct |
103 ms |
28036 KB |
Output is correct |
75 |
Correct |
156 ms |
28036 KB |
Output is correct |
76 |
Correct |
139 ms |
28036 KB |
Output is correct |
77 |
Correct |
56 ms |
28036 KB |
Output is correct |
78 |
Correct |
136 ms |
28036 KB |
Output is correct |
79 |
Correct |
136 ms |
28036 KB |
Output is correct |
80 |
Correct |
136 ms |
28036 KB |
Output is correct |
81 |
Correct |
29 ms |
28036 KB |
Output is correct |
82 |
Correct |
93 ms |
28036 KB |
Output is correct |
83 |
Correct |
139 ms |
28036 KB |
Output is correct |
84 |
Correct |
143 ms |
28036 KB |
Output is correct |
85 |
Correct |
139 ms |
28036 KB |
Output is correct |
86 |
Correct |
139 ms |
28036 KB |
Output is correct |
87 |
Correct |
126 ms |
28036 KB |
Output is correct |
88 |
Correct |
23 ms |
28036 KB |
Output is correct |
89 |
Correct |
96 ms |
28036 KB |
Output is correct |
90 |
Correct |
43 ms |
28036 KB |
Output is correct |
91 |
Correct |
6 ms |
28036 KB |
Output is correct |
92 |
Correct |
66 ms |
28036 KB |
Output is correct |