#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
int a[3][200001];
long long f(int l, int r, int le, int re, std::vector<int> &res)
{
if(l==r)
{
res.push_back(l);
return a[le+re][l];
}
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)
{
res.push_back(l);
res.push_back(r);
return t1;
}
else
{
res.push_back(r);
res.push_back(l);
return t2;
}
}
int x = (l+r)/2;
long long tl0, tl1, tr0, tr1;
std::vector<int> le0, le1, re0, re1;
tl0 = f(l, x-1, le, 0, le0);
tl1 = f(l, x-1, le, 1, le1);
tr0 = f(x+1, r, 0, re, re0);
tr1 = f(x+1, r, 1, re, re1);
long long p1 = 0LL + a[2][x] + tl0 + tr0;
long long p2 = 0LL + a[1][x] + tl1 + tr0;
long long p3 = 0LL + a[0][x] + tl1 + tr1;
long long p4 = 0LL + a[1][x] + tl0 + tr1;
long long p5 = 0LL + a[0][x] + tl1 + tr1;
long long pm = std::max({p1, p2, p3, p4, p5});
if(p1 == pm)
{
res.push_back(x);
res.insert(res.end(), le0.begin(), le0.end());
res.insert(res.end(), re0.begin(), re0.end());
}
else if(p2 == pm)
{
res.insert(res.end(), le1.begin(), le1.end());
res.push_back(x);
res.insert(res.end(), re0.begin(), re0.end());
}
else if(p3 == pm)
{
res.insert(res.end(), le1.begin(), le1.end());
res.insert(res.end(), re1.begin(), re1.end());
res.push_back(x);
}
else if(p4 == pm)
{
res.insert(res.end(), re1.begin(), re1.end());
res.push_back(x);
res.insert(res.end(), le0.begin(), le0.end());
}
else if(p5 == pm)
{
res.insert(res.end(), re1.begin(), re1.end());
res.insert(res.end(), le1.begin(), le1.end());
res.push_back(x);
}
return pm;
}
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]);
long long r;
std::vector<int> res;
r = f(1, n, 1, 1, res);
printf("%lld\n", r);
for(int &v : res)
printf("%d ", v);
return 0;
}
Compilation message
space.cpp: In function 'int main()':
space.cpp:89:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
space.cpp:91: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]);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4280 KB |
Output is correct |
2 |
Correct |
0 ms |
4280 KB |
Output is correct |
3 |
Correct |
0 ms |
4280 KB |
Output is correct |
4 |
Correct |
0 ms |
4280 KB |
Output is correct |
5 |
Correct |
0 ms |
4280 KB |
Output is correct |
6 |
Correct |
0 ms |
4280 KB |
Output is correct |
7 |
Correct |
0 ms |
4280 KB |
Output is correct |
8 |
Correct |
0 ms |
4280 KB |
Output is correct |
9 |
Correct |
0 ms |
4280 KB |
Output is correct |
10 |
Correct |
0 ms |
4280 KB |
Output is correct |
11 |
Correct |
0 ms |
4280 KB |
Output is correct |
12 |
Correct |
0 ms |
4280 KB |
Output is correct |
13 |
Correct |
0 ms |
4280 KB |
Output is correct |
14 |
Correct |
0 ms |
4280 KB |
Output is correct |
15 |
Correct |
0 ms |
4280 KB |
Output is correct |
16 |
Correct |
0 ms |
4280 KB |
Output is correct |
17 |
Correct |
0 ms |
4280 KB |
Output is correct |
18 |
Correct |
0 ms |
4280 KB |
Output is correct |
19 |
Correct |
0 ms |
4280 KB |
Output is correct |
20 |
Correct |
0 ms |
4280 KB |
Output is correct |
21 |
Correct |
0 ms |
4280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4280 KB |
Output is correct |
2 |
Correct |
0 ms |
4280 KB |
Output is correct |
3 |
Correct |
0 ms |
4280 KB |
Output is correct |
4 |
Correct |
0 ms |
4280 KB |
Output is correct |
5 |
Correct |
0 ms |
4280 KB |
Output is correct |
6 |
Correct |
0 ms |
4280 KB |
Output is correct |
7 |
Correct |
0 ms |
4280 KB |
Output is correct |
8 |
Correct |
0 ms |
4280 KB |
Output is correct |
9 |
Correct |
0 ms |
4280 KB |
Output is correct |
10 |
Correct |
0 ms |
4280 KB |
Output is correct |
11 |
Correct |
0 ms |
4280 KB |
Output is correct |
12 |
Correct |
0 ms |
4280 KB |
Output is correct |
13 |
Correct |
0 ms |
4280 KB |
Output is correct |
14 |
Correct |
0 ms |
4280 KB |
Output is correct |
15 |
Correct |
0 ms |
4280 KB |
Output is correct |
16 |
Correct |
0 ms |
4280 KB |
Output is correct |
17 |
Correct |
0 ms |
4280 KB |
Output is correct |
18 |
Correct |
0 ms |
4280 KB |
Output is correct |
19 |
Correct |
0 ms |
4280 KB |
Output is correct |
20 |
Correct |
0 ms |
4280 KB |
Output is correct |
21 |
Correct |
0 ms |
4280 KB |
Output is correct |
22 |
Correct |
0 ms |
4280 KB |
Output is correct |
23 |
Correct |
0 ms |
4280 KB |
Output is correct |
24 |
Correct |
0 ms |
4280 KB |
Output is correct |
25 |
Correct |
0 ms |
4280 KB |
Output is correct |
26 |
Correct |
0 ms |
4280 KB |
Output is correct |
27 |
Correct |
0 ms |
4280 KB |
Output is correct |
28 |
Correct |
0 ms |
4280 KB |
Output is correct |
29 |
Correct |
0 ms |
4280 KB |
Output is correct |
30 |
Correct |
0 ms |
4280 KB |
Output is correct |
31 |
Correct |
0 ms |
4280 KB |
Output is correct |
32 |
Correct |
0 ms |
4280 KB |
Output is correct |
33 |
Correct |
0 ms |
4280 KB |
Output is correct |
34 |
Correct |
0 ms |
4280 KB |
Output is correct |
35 |
Correct |
0 ms |
4280 KB |
Output is correct |
36 |
Correct |
0 ms |
4280 KB |
Output is correct |
37 |
Correct |
0 ms |
4280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4280 KB |
Output is correct |
2 |
Correct |
0 ms |
4280 KB |
Output is correct |
3 |
Correct |
0 ms |
4280 KB |
Output is correct |
4 |
Correct |
0 ms |
4280 KB |
Output is correct |
5 |
Correct |
0 ms |
4280 KB |
Output is correct |
6 |
Correct |
0 ms |
4280 KB |
Output is correct |
7 |
Correct |
0 ms |
4280 KB |
Output is correct |
8 |
Correct |
0 ms |
4280 KB |
Output is correct |
9 |
Correct |
0 ms |
4280 KB |
Output is correct |
10 |
Correct |
0 ms |
4280 KB |
Output is correct |
11 |
Correct |
0 ms |
4280 KB |
Output is correct |
12 |
Correct |
0 ms |
4280 KB |
Output is correct |
13 |
Correct |
0 ms |
4280 KB |
Output is correct |
14 |
Correct |
0 ms |
4280 KB |
Output is correct |
15 |
Correct |
0 ms |
4280 KB |
Output is correct |
16 |
Correct |
0 ms |
4280 KB |
Output is correct |
17 |
Correct |
0 ms |
4280 KB |
Output is correct |
18 |
Correct |
0 ms |
4280 KB |
Output is correct |
19 |
Correct |
0 ms |
4280 KB |
Output is correct |
20 |
Correct |
0 ms |
4280 KB |
Output is correct |
21 |
Correct |
0 ms |
4280 KB |
Output is correct |
22 |
Correct |
0 ms |
4280 KB |
Output is correct |
23 |
Correct |
0 ms |
4280 KB |
Output is correct |
24 |
Correct |
0 ms |
4280 KB |
Output is correct |
25 |
Correct |
0 ms |
4280 KB |
Output is correct |
26 |
Correct |
0 ms |
4280 KB |
Output is correct |
27 |
Correct |
0 ms |
4280 KB |
Output is correct |
28 |
Correct |
0 ms |
4280 KB |
Output is correct |
29 |
Correct |
0 ms |
4280 KB |
Output is correct |
30 |
Correct |
0 ms |
4280 KB |
Output is correct |
31 |
Correct |
0 ms |
4280 KB |
Output is correct |
32 |
Correct |
0 ms |
4280 KB |
Output is correct |
33 |
Correct |
0 ms |
4280 KB |
Output is correct |
34 |
Correct |
0 ms |
4280 KB |
Output is correct |
35 |
Correct |
0 ms |
4280 KB |
Output is correct |
36 |
Correct |
0 ms |
4280 KB |
Output is correct |
37 |
Correct |
0 ms |
4280 KB |
Output is correct |
38 |
Correct |
0 ms |
4280 KB |
Output is correct |
39 |
Correct |
0 ms |
4280 KB |
Output is correct |
40 |
Correct |
0 ms |
4280 KB |
Output is correct |
41 |
Correct |
0 ms |
4280 KB |
Output is correct |
42 |
Correct |
0 ms |
4280 KB |
Output is correct |
43 |
Correct |
0 ms |
4280 KB |
Output is correct |
44 |
Correct |
0 ms |
4280 KB |
Output is correct |
45 |
Correct |
0 ms |
4280 KB |
Output is correct |
46 |
Correct |
0 ms |
4280 KB |
Output is correct |
47 |
Correct |
0 ms |
4280 KB |
Output is correct |
48 |
Correct |
0 ms |
4280 KB |
Output is correct |
49 |
Correct |
0 ms |
4280 KB |
Output is correct |
50 |
Correct |
0 ms |
4280 KB |
Output is correct |
51 |
Correct |
0 ms |
4280 KB |
Output is correct |
52 |
Correct |
0 ms |
4280 KB |
Output is correct |
53 |
Correct |
0 ms |
4280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4280 KB |
Output is correct |
2 |
Correct |
0 ms |
4280 KB |
Output is correct |
3 |
Correct |
0 ms |
4280 KB |
Output is correct |
4 |
Correct |
0 ms |
4280 KB |
Output is correct |
5 |
Correct |
0 ms |
4280 KB |
Output is correct |
6 |
Correct |
0 ms |
4280 KB |
Output is correct |
7 |
Correct |
0 ms |
4280 KB |
Output is correct |
8 |
Correct |
0 ms |
4280 KB |
Output is correct |
9 |
Correct |
0 ms |
4280 KB |
Output is correct |
10 |
Correct |
0 ms |
4280 KB |
Output is correct |
11 |
Correct |
0 ms |
4280 KB |
Output is correct |
12 |
Correct |
0 ms |
4280 KB |
Output is correct |
13 |
Correct |
0 ms |
4280 KB |
Output is correct |
14 |
Correct |
0 ms |
4280 KB |
Output is correct |
15 |
Correct |
0 ms |
4280 KB |
Output is correct |
16 |
Correct |
0 ms |
4280 KB |
Output is correct |
17 |
Correct |
0 ms |
4280 KB |
Output is correct |
18 |
Correct |
0 ms |
4280 KB |
Output is correct |
19 |
Correct |
0 ms |
4280 KB |
Output is correct |
20 |
Correct |
0 ms |
4280 KB |
Output is correct |
21 |
Correct |
0 ms |
4280 KB |
Output is correct |
22 |
Correct |
0 ms |
4280 KB |
Output is correct |
23 |
Correct |
0 ms |
4280 KB |
Output is correct |
24 |
Correct |
0 ms |
4280 KB |
Output is correct |
25 |
Correct |
0 ms |
4280 KB |
Output is correct |
26 |
Correct |
0 ms |
4280 KB |
Output is correct |
27 |
Correct |
0 ms |
4280 KB |
Output is correct |
28 |
Correct |
0 ms |
4280 KB |
Output is correct |
29 |
Correct |
0 ms |
4280 KB |
Output is correct |
30 |
Correct |
0 ms |
4280 KB |
Output is correct |
31 |
Correct |
0 ms |
4280 KB |
Output is correct |
32 |
Correct |
0 ms |
4280 KB |
Output is correct |
33 |
Correct |
0 ms |
4280 KB |
Output is correct |
34 |
Correct |
0 ms |
4280 KB |
Output is correct |
35 |
Correct |
0 ms |
4280 KB |
Output is correct |
36 |
Correct |
0 ms |
4280 KB |
Output is correct |
37 |
Correct |
0 ms |
4280 KB |
Output is correct |
38 |
Correct |
0 ms |
4280 KB |
Output is correct |
39 |
Correct |
0 ms |
4280 KB |
Output is correct |
40 |
Correct |
0 ms |
4280 KB |
Output is correct |
41 |
Correct |
0 ms |
4280 KB |
Output is correct |
42 |
Correct |
0 ms |
4280 KB |
Output is correct |
43 |
Correct |
0 ms |
4280 KB |
Output is correct |
44 |
Correct |
0 ms |
4280 KB |
Output is correct |
45 |
Correct |
0 ms |
4280 KB |
Output is correct |
46 |
Correct |
0 ms |
4280 KB |
Output is correct |
47 |
Correct |
0 ms |
4280 KB |
Output is correct |
48 |
Correct |
0 ms |
4280 KB |
Output is correct |
49 |
Correct |
0 ms |
4280 KB |
Output is correct |
50 |
Correct |
0 ms |
4280 KB |
Output is correct |
51 |
Correct |
0 ms |
4280 KB |
Output is correct |
52 |
Correct |
0 ms |
4280 KB |
Output is correct |
53 |
Correct |
0 ms |
4280 KB |
Output is correct |
54 |
Correct |
0 ms |
4280 KB |
Output is correct |
55 |
Execution timed out |
1000 ms |
4580 KB |
Execution timed out |
56 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
57 |
Execution timed out |
1000 ms |
4552 KB |
Execution timed out |
58 |
Execution timed out |
1000 ms |
4524 KB |
Execution timed out |
59 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
60 |
Execution timed out |
1000 ms |
4524 KB |
Execution timed out |
61 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
62 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
63 |
Correct |
89 ms |
4420 KB |
Output is correct |
64 |
Execution timed out |
1000 ms |
4520 KB |
Execution timed out |
65 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
66 |
Execution timed out |
1000 ms |
4564 KB |
Execution timed out |
67 |
Correct |
519 ms |
4412 KB |
Output is correct |
68 |
Correct |
176 ms |
4420 KB |
Output is correct |
69 |
Execution timed out |
1000 ms |
4420 KB |
Execution timed out |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4280 KB |
Output is correct |
2 |
Correct |
0 ms |
4280 KB |
Output is correct |
3 |
Correct |
0 ms |
4280 KB |
Output is correct |
4 |
Correct |
0 ms |
4280 KB |
Output is correct |
5 |
Correct |
0 ms |
4280 KB |
Output is correct |
6 |
Correct |
0 ms |
4280 KB |
Output is correct |
7 |
Correct |
0 ms |
4280 KB |
Output is correct |
8 |
Correct |
0 ms |
4280 KB |
Output is correct |
9 |
Correct |
0 ms |
4280 KB |
Output is correct |
10 |
Correct |
0 ms |
4280 KB |
Output is correct |
11 |
Correct |
0 ms |
4280 KB |
Output is correct |
12 |
Correct |
0 ms |
4280 KB |
Output is correct |
13 |
Correct |
0 ms |
4280 KB |
Output is correct |
14 |
Correct |
0 ms |
4280 KB |
Output is correct |
15 |
Correct |
0 ms |
4280 KB |
Output is correct |
16 |
Correct |
0 ms |
4280 KB |
Output is correct |
17 |
Correct |
0 ms |
4280 KB |
Output is correct |
18 |
Correct |
0 ms |
4280 KB |
Output is correct |
19 |
Correct |
0 ms |
4280 KB |
Output is correct |
20 |
Correct |
0 ms |
4280 KB |
Output is correct |
21 |
Correct |
0 ms |
4280 KB |
Output is correct |
22 |
Correct |
0 ms |
4280 KB |
Output is correct |
23 |
Correct |
0 ms |
4280 KB |
Output is correct |
24 |
Correct |
0 ms |
4280 KB |
Output is correct |
25 |
Correct |
0 ms |
4280 KB |
Output is correct |
26 |
Correct |
0 ms |
4280 KB |
Output is correct |
27 |
Correct |
0 ms |
4280 KB |
Output is correct |
28 |
Correct |
0 ms |
4280 KB |
Output is correct |
29 |
Correct |
0 ms |
4280 KB |
Output is correct |
30 |
Correct |
0 ms |
4280 KB |
Output is correct |
31 |
Correct |
0 ms |
4280 KB |
Output is correct |
32 |
Correct |
0 ms |
4280 KB |
Output is correct |
33 |
Correct |
0 ms |
4280 KB |
Output is correct |
34 |
Correct |
0 ms |
4280 KB |
Output is correct |
35 |
Correct |
0 ms |
4280 KB |
Output is correct |
36 |
Correct |
0 ms |
4280 KB |
Output is correct |
37 |
Correct |
0 ms |
4280 KB |
Output is correct |
38 |
Correct |
0 ms |
4280 KB |
Output is correct |
39 |
Correct |
0 ms |
4280 KB |
Output is correct |
40 |
Correct |
0 ms |
4280 KB |
Output is correct |
41 |
Correct |
0 ms |
4280 KB |
Output is correct |
42 |
Correct |
0 ms |
4280 KB |
Output is correct |
43 |
Correct |
0 ms |
4280 KB |
Output is correct |
44 |
Correct |
0 ms |
4280 KB |
Output is correct |
45 |
Correct |
0 ms |
4280 KB |
Output is correct |
46 |
Correct |
0 ms |
4280 KB |
Output is correct |
47 |
Correct |
0 ms |
4280 KB |
Output is correct |
48 |
Correct |
0 ms |
4280 KB |
Output is correct |
49 |
Correct |
0 ms |
4280 KB |
Output is correct |
50 |
Correct |
0 ms |
4280 KB |
Output is correct |
51 |
Correct |
0 ms |
4280 KB |
Output is correct |
52 |
Correct |
0 ms |
4280 KB |
Output is correct |
53 |
Correct |
0 ms |
4280 KB |
Output is correct |
54 |
Correct |
0 ms |
4280 KB |
Output is correct |
55 |
Execution timed out |
1000 ms |
4580 KB |
Execution timed out |
56 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
57 |
Execution timed out |
1000 ms |
4552 KB |
Execution timed out |
58 |
Execution timed out |
1000 ms |
4524 KB |
Execution timed out |
59 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
60 |
Execution timed out |
1000 ms |
4524 KB |
Execution timed out |
61 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
62 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
63 |
Correct |
89 ms |
4420 KB |
Output is correct |
64 |
Execution timed out |
1000 ms |
4520 KB |
Execution timed out |
65 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
66 |
Execution timed out |
1000 ms |
4564 KB |
Execution timed out |
67 |
Correct |
519 ms |
4412 KB |
Output is correct |
68 |
Correct |
176 ms |
4420 KB |
Output is correct |
69 |
Execution timed out |
1000 ms |
4420 KB |
Execution timed out |
70 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
71 |
Execution timed out |
1000 ms |
4592 KB |
Execution timed out |
72 |
Execution timed out |
1000 ms |
4416 KB |
Execution timed out |
73 |
Execution timed out |
1000 ms |
4524 KB |
Execution timed out |
74 |
Execution timed out |
1000 ms |
4520 KB |
Execution timed out |
75 |
Execution timed out |
1000 ms |
4512 KB |
Execution timed out |
76 |
Execution timed out |
1000 ms |
4536 KB |
Execution timed out |
77 |
Execution timed out |
1000 ms |
4424 KB |
Execution timed out |
78 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
79 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
80 |
Execution timed out |
1000 ms |
4416 KB |
Execution timed out |
81 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
82 |
Execution timed out |
1000 ms |
4572 KB |
Execution timed out |
83 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
84 |
Execution timed out |
1000 ms |
4548 KB |
Execution timed out |
85 |
Execution timed out |
1000 ms |
4512 KB |
Execution timed out |
86 |
Execution timed out |
1000 ms |
4596 KB |
Execution timed out |
87 |
Execution timed out |
1000 ms |
4532 KB |
Execution timed out |
88 |
Execution timed out |
1000 ms |
4528 KB |
Execution timed out |
89 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
90 |
Execution timed out |
1000 ms |
4416 KB |
Execution timed out |
91 |
Execution timed out |
1000 ms |
4412 KB |
Execution timed out |
92 |
Execution timed out |
1000 ms |
4416 KB |
Execution timed out |