Submission #20423

# Submission time Handle Problem Language Result Execution time Memory
20423 2017-02-11T11:09:27 Z KDH(#46, kdh9949) Can polan into space? (OJUZ11_space) C++14
0 / 100
156 ms 30024 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;
ll a[200010][3], b[200010][3], ldp[200010][2], rdp[200010][2];
int lbx[200010][2], lby[200010][2], rbx[200010][2], rby[200010][2];
ll inf = (1LL << 60);

void cal(ll dp[200010][2], int bx[200010][2], int by[200010][2], ll c[200010][3]){
	dp[0][1] = dp[1][1] = -inf;
    for(int i = 1; i <= n + 1; i++){
        dp[i][0] = dp[i - 1][0] + c[i][1]; bx[i][0] = i - 1; by[i][0] = 0;
        if(i > 1 && dp[i][0] < dp[i - 1][1] + c[i - 2][2] + c[i][1]){
			dp[i][0] = dp[i - 1][1] + c[i - 2][2] + c[i][1];
			bx[i][0] = i - 1; by[i][0] = 1;
		}
		if(i > 1) dp[i][1] = dp[i - 2][0] + c[i][0]; bx[i][1] = i - 2; by[i][1] = 0;
		if(i > 2 && dp[i][1] < dp[i - 2][1] + c[i - 3][2] + c[i][0]){
			dp[i][1] = dp[i - 2][1] + c[i - 3][2] + c[i][0];
			bx[i][1] = i - 2; by[i][1] = 1;
		}
    }
}

void btk(int flag, int bx[200010][2], int by[200010][2], int x, int y){
	if(!x) return;
	btk(flag, bx, by, bx[x][y], by[x][y]);
	for(int i = x - 1; i >= max(1, bx[x][y]); i--) printf("%d ", flag ? n + 1 - i : i);
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < 3; j++){
			scanf("%lld", a[i] + j);
			b[n + 1 - i][j] = a[i][j];
		}
	}
	if(n == 1){
		printf("%lld\n1\n", a[1][0]);
		return 0;
	}
	a[1][2] = a[1][1]; //a[n][2] = a[n][1];
	a[1][1] = a[1][0]; //a[n][1] = a[n][0];
	b[1][2] = b[1][1]; //b[n][2] = b[n][1];
	b[1][1] = b[1][0]; //b[n][1] = b[n][0];
	cal(ldp, lbx, lby, a);
	cal(rdp, rbx, rby, b);
	ll mx = -1, mi;
	for(int i = 1; i <= n; i++){
		//printf("%lld %lld %lld\n", ldp[i][0] - a[i][1], rdp[n + 1 - i][0] - b[n + 1 - i][1], a[i][2]);
		if(mx < (ldp[i][0] - a[i][1]) + (rdp[n + 1 - i][0] - b[n + 1 - i][1]) + a[i][2]){
			mx = (ldp[i][0] - a[i][1]) + (rdp[n + 1 - i][0] - b[n + 1 - i][1] + a[i][2]);
			mi = i;
		}
	}
	printf("%lld\n", mx);
	btk(0, lbx, lby, mi, 0);
	btk(1, rbx, rby, n + 1 - mi, 0);
	printf("%d\n", mi);
}

Compilation message

space.cpp: In function 'int main()':
space.cpp:61:19: warning: format '%d' expects argument of type 'int', but argument 2 has type 'll {aka long long int}' [-Wformat=]
  printf("%d\n", mi);
                   ^
space.cpp:33:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
space.cpp:36:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld", a[i] + j);
                           ^
space.cpp:60:5: warning: 'mi' may be used uninitialized in this function [-Wmaybe-uninitialized]
  btk(1, rbx, rby, n + 1 - mi, 0);
     ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 23896 KB Output is correct
2 Incorrect 0 ms 23896 KB Output isn't correct
3 Correct 0 ms 23896 KB Output is correct
4 Incorrect 0 ms 23896 KB Output isn't correct
5 Incorrect 0 ms 23896 KB Output isn't correct
6 Incorrect 0 ms 23896 KB Output isn't correct
7 Incorrect 0 ms 23896 KB Output isn't correct
8 Incorrect 0 ms 23896 KB Output isn't correct
9 Correct 0 ms 23896 KB Output is correct
10 Correct 0 ms 23896 KB Output is correct
11 Incorrect 0 ms 23896 KB Output isn't correct
12 Incorrect 0 ms 23896 KB Output isn't correct
13 Incorrect 0 ms 23896 KB Output isn't correct
14 Incorrect 0 ms 23896 KB Output isn't correct
15 Incorrect 0 ms 23896 KB Output isn't correct
16 Correct 0 ms 23896 KB Output is correct
17 Incorrect 0 ms 23896 KB Output isn't correct
18 Incorrect 0 ms 23896 KB Output isn't correct
19 Incorrect 0 ms 23896 KB Output isn't correct
20 Incorrect 0 ms 23896 KB Output isn't correct
21 Incorrect 0 ms 23896 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 23896 KB Output is correct
2 Incorrect 0 ms 23896 KB Output isn't correct
3 Correct 0 ms 23896 KB Output is correct
4 Incorrect 0 ms 23896 KB Output isn't correct
5 Incorrect 0 ms 23896 KB Output isn't correct
6 Incorrect 0 ms 23896 KB Output isn't correct
7 Incorrect 0 ms 23896 KB Output isn't correct
8 Incorrect 0 ms 23896 KB Output isn't correct
9 Correct 0 ms 23896 KB Output is correct
10 Correct 0 ms 23896 KB Output is correct
11 Incorrect 0 ms 23896 KB Output isn't correct
12 Incorrect 0 ms 23896 KB Output isn't correct
13 Incorrect 0 ms 23896 KB Output isn't correct
14 Incorrect 0 ms 23896 KB Output isn't correct
15 Incorrect 0 ms 23896 KB Output isn't correct
16 Correct 0 ms 23896 KB Output is correct
17 Incorrect 0 ms 23896 KB Output isn't correct
18 Incorrect 0 ms 23896 KB Output isn't correct
19 Incorrect 0 ms 23896 KB Output isn't correct
20 Incorrect 0 ms 23896 KB Output isn't correct
21 Incorrect 0 ms 23896 KB Output isn't correct
22 Incorrect 0 ms 23896 KB Output isn't correct
23 Incorrect 0 ms 23896 KB Output isn't correct
24 Incorrect 0 ms 23896 KB Output isn't correct
25 Incorrect 0 ms 23896 KB Output isn't correct
26 Incorrect 0 ms 23896 KB Output isn't correct
27 Incorrect 0 ms 23896 KB Output isn't correct
28 Correct 0 ms 23896 KB Output is correct
29 Incorrect 0 ms 23896 KB Output isn't correct
30 Incorrect 0 ms 23896 KB Output isn't correct
31 Correct 0 ms 23896 KB Output is correct
32 Incorrect 0 ms 23896 KB Output isn't correct
33 Incorrect 0 ms 23896 KB Output isn't correct
34 Incorrect 0 ms 23896 KB Output isn't correct
35 Incorrect 0 ms 23896 KB Output isn't correct
36 Incorrect 0 ms 23896 KB Output isn't correct
37 Incorrect 0 ms 23896 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 23896 KB Output is correct
2 Incorrect 0 ms 23896 KB Output isn't correct
3 Correct 0 ms 23896 KB Output is correct
4 Incorrect 0 ms 23896 KB Output isn't correct
5 Incorrect 0 ms 23896 KB Output isn't correct
6 Incorrect 0 ms 23896 KB Output isn't correct
7 Incorrect 0 ms 23896 KB Output isn't correct
8 Incorrect 0 ms 23896 KB Output isn't correct
9 Correct 0 ms 23896 KB Output is correct
10 Correct 0 ms 23896 KB Output is correct
11 Incorrect 0 ms 23896 KB Output isn't correct
12 Incorrect 0 ms 23896 KB Output isn't correct
13 Incorrect 0 ms 23896 KB Output isn't correct
14 Incorrect 0 ms 23896 KB Output isn't correct
15 Incorrect 0 ms 23896 KB Output isn't correct
16 Correct 0 ms 23896 KB Output is correct
17 Incorrect 0 ms 23896 KB Output isn't correct
18 Incorrect 0 ms 23896 KB Output isn't correct
19 Incorrect 0 ms 23896 KB Output isn't correct
20 Incorrect 0 ms 23896 KB Output isn't correct
21 Incorrect 0 ms 23896 KB Output isn't correct
22 Incorrect 0 ms 23896 KB Output isn't correct
23 Incorrect 0 ms 23896 KB Output isn't correct
24 Incorrect 0 ms 23896 KB Output isn't correct
25 Incorrect 0 ms 23896 KB Output isn't correct
26 Incorrect 0 ms 23896 KB Output isn't correct
27 Incorrect 0 ms 23896 KB Output isn't correct
28 Correct 0 ms 23896 KB Output is correct
29 Incorrect 0 ms 23896 KB Output isn't correct
30 Incorrect 0 ms 23896 KB Output isn't correct
31 Correct 0 ms 23896 KB Output is correct
32 Incorrect 0 ms 23896 KB Output isn't correct
33 Incorrect 0 ms 23896 KB Output isn't correct
34 Incorrect 0 ms 23896 KB Output isn't correct
35 Incorrect 0 ms 23896 KB Output isn't correct
36 Incorrect 0 ms 23896 KB Output isn't correct
37 Incorrect 0 ms 23896 KB Output isn't correct
38 Incorrect 0 ms 23896 KB Output isn't correct
39 Incorrect 0 ms 23896 KB Output isn't correct
40 Correct 0 ms 23896 KB Output is correct
41 Incorrect 0 ms 23896 KB Output isn't correct
42 Incorrect 0 ms 23896 KB Output isn't correct
43 Incorrect 0 ms 23896 KB Output isn't correct
44 Correct 0 ms 23896 KB Output is correct
45 Incorrect 0 ms 23896 KB Output isn't correct
46 Incorrect 0 ms 23896 KB Output isn't correct
47 Incorrect 0 ms 23896 KB Output isn't correct
48 Incorrect 0 ms 23896 KB Output isn't correct
49 Incorrect 0 ms 23896 KB Output isn't correct
50 Incorrect 0 ms 23896 KB Output isn't correct
51 Incorrect 0 ms 23896 KB Output isn't correct
52 Incorrect 0 ms 23896 KB Output isn't correct
53 Incorrect 0 ms 23896 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 23896 KB Output is correct
2 Incorrect 0 ms 23896 KB Output isn't correct
3 Correct 0 ms 23896 KB Output is correct
4 Incorrect 0 ms 23896 KB Output isn't correct
5 Incorrect 0 ms 23896 KB Output isn't correct
6 Incorrect 0 ms 23896 KB Output isn't correct
7 Incorrect 0 ms 23896 KB Output isn't correct
8 Incorrect 0 ms 23896 KB Output isn't correct
9 Correct 0 ms 23896 KB Output is correct
10 Correct 0 ms 23896 KB Output is correct
11 Incorrect 0 ms 23896 KB Output isn't correct
12 Incorrect 0 ms 23896 KB Output isn't correct
13 Incorrect 0 ms 23896 KB Output isn't correct
14 Incorrect 0 ms 23896 KB Output isn't correct
15 Incorrect 0 ms 23896 KB Output isn't correct
16 Correct 0 ms 23896 KB Output is correct
17 Incorrect 0 ms 23896 KB Output isn't correct
18 Incorrect 0 ms 23896 KB Output isn't correct
19 Incorrect 0 ms 23896 KB Output isn't correct
20 Incorrect 0 ms 23896 KB Output isn't correct
21 Incorrect 0 ms 23896 KB Output isn't correct
22 Incorrect 0 ms 23896 KB Output isn't correct
23 Incorrect 0 ms 23896 KB Output isn't correct
24 Incorrect 0 ms 23896 KB Output isn't correct
25 Incorrect 0 ms 23896 KB Output isn't correct
26 Incorrect 0 ms 23896 KB Output isn't correct
27 Incorrect 0 ms 23896 KB Output isn't correct
28 Correct 0 ms 23896 KB Output is correct
29 Incorrect 0 ms 23896 KB Output isn't correct
30 Incorrect 0 ms 23896 KB Output isn't correct
31 Correct 0 ms 23896 KB Output is correct
32 Incorrect 0 ms 23896 KB Output isn't correct
33 Incorrect 0 ms 23896 KB Output isn't correct
34 Incorrect 0 ms 23896 KB Output isn't correct
35 Incorrect 0 ms 23896 KB Output isn't correct
36 Incorrect 0 ms 23896 KB Output isn't correct
37 Incorrect 0 ms 23896 KB Output isn't correct
38 Incorrect 0 ms 23896 KB Output isn't correct
39 Incorrect 0 ms 23896 KB Output isn't correct
40 Correct 0 ms 23896 KB Output is correct
41 Incorrect 0 ms 23896 KB Output isn't correct
42 Incorrect 0 ms 23896 KB Output isn't correct
43 Incorrect 0 ms 23896 KB Output isn't correct
44 Correct 0 ms 23896 KB Output is correct
45 Incorrect 0 ms 23896 KB Output isn't correct
46 Incorrect 0 ms 23896 KB Output isn't correct
47 Incorrect 0 ms 23896 KB Output isn't correct
48 Incorrect 0 ms 23896 KB Output isn't correct
49 Incorrect 0 ms 23896 KB Output isn't correct
50 Incorrect 0 ms 23896 KB Output isn't correct
51 Incorrect 0 ms 23896 KB Output isn't correct
52 Incorrect 0 ms 23896 KB Output isn't correct
53 Incorrect 0 ms 23896 KB Output isn't correct
54 Incorrect 0 ms 23896 KB Output isn't correct
55 Incorrect 6 ms 23928 KB Output isn't correct
56 Incorrect 6 ms 24080 KB Output isn't correct
57 Incorrect 6 ms 23988 KB Output isn't correct
58 Incorrect 6 ms 23992 KB Output isn't correct
59 Incorrect 3 ms 23912 KB Output isn't correct
60 Incorrect 6 ms 23896 KB Output isn't correct
61 Correct 3 ms 24084 KB Output is correct
62 Incorrect 3 ms 23900 KB Output isn't correct
63 Incorrect 0 ms 23896 KB Output isn't correct
64 Incorrect 6 ms 23916 KB Output isn't correct
65 Correct 3 ms 24088 KB Output is correct
66 Incorrect 9 ms 23964 KB Output isn't correct
67 Incorrect 3 ms 23896 KB Output isn't correct
68 Incorrect 0 ms 23896 KB Output isn't correct
69 Incorrect 6 ms 23932 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 23896 KB Output is correct
2 Incorrect 0 ms 23896 KB Output isn't correct
3 Correct 0 ms 23896 KB Output is correct
4 Incorrect 0 ms 23896 KB Output isn't correct
5 Incorrect 0 ms 23896 KB Output isn't correct
6 Incorrect 0 ms 23896 KB Output isn't correct
7 Incorrect 0 ms 23896 KB Output isn't correct
8 Incorrect 0 ms 23896 KB Output isn't correct
9 Correct 0 ms 23896 KB Output is correct
10 Correct 0 ms 23896 KB Output is correct
11 Incorrect 0 ms 23896 KB Output isn't correct
12 Incorrect 0 ms 23896 KB Output isn't correct
13 Incorrect 0 ms 23896 KB Output isn't correct
14 Incorrect 0 ms 23896 KB Output isn't correct
15 Incorrect 0 ms 23896 KB Output isn't correct
16 Correct 0 ms 23896 KB Output is correct
17 Incorrect 0 ms 23896 KB Output isn't correct
18 Incorrect 0 ms 23896 KB Output isn't correct
19 Incorrect 0 ms 23896 KB Output isn't correct
20 Incorrect 0 ms 23896 KB Output isn't correct
21 Incorrect 0 ms 23896 KB Output isn't correct
22 Incorrect 0 ms 23896 KB Output isn't correct
23 Incorrect 0 ms 23896 KB Output isn't correct
24 Incorrect 0 ms 23896 KB Output isn't correct
25 Incorrect 0 ms 23896 KB Output isn't correct
26 Incorrect 0 ms 23896 KB Output isn't correct
27 Incorrect 0 ms 23896 KB Output isn't correct
28 Correct 0 ms 23896 KB Output is correct
29 Incorrect 0 ms 23896 KB Output isn't correct
30 Incorrect 0 ms 23896 KB Output isn't correct
31 Correct 0 ms 23896 KB Output is correct
32 Incorrect 0 ms 23896 KB Output isn't correct
33 Incorrect 0 ms 23896 KB Output isn't correct
34 Incorrect 0 ms 23896 KB Output isn't correct
35 Incorrect 0 ms 23896 KB Output isn't correct
36 Incorrect 0 ms 23896 KB Output isn't correct
37 Incorrect 0 ms 23896 KB Output isn't correct
38 Incorrect 0 ms 23896 KB Output isn't correct
39 Incorrect 0 ms 23896 KB Output isn't correct
40 Correct 0 ms 23896 KB Output is correct
41 Incorrect 0 ms 23896 KB Output isn't correct
42 Incorrect 0 ms 23896 KB Output isn't correct
43 Incorrect 0 ms 23896 KB Output isn't correct
44 Correct 0 ms 23896 KB Output is correct
45 Incorrect 0 ms 23896 KB Output isn't correct
46 Incorrect 0 ms 23896 KB Output isn't correct
47 Incorrect 0 ms 23896 KB Output isn't correct
48 Incorrect 0 ms 23896 KB Output isn't correct
49 Incorrect 0 ms 23896 KB Output isn't correct
50 Incorrect 0 ms 23896 KB Output isn't correct
51 Incorrect 0 ms 23896 KB Output isn't correct
52 Incorrect 0 ms 23896 KB Output isn't correct
53 Incorrect 0 ms 23896 KB Output isn't correct
54 Incorrect 0 ms 23896 KB Output isn't correct
55 Incorrect 6 ms 23928 KB Output isn't correct
56 Incorrect 6 ms 24080 KB Output isn't correct
57 Incorrect 6 ms 23988 KB Output isn't correct
58 Incorrect 6 ms 23992 KB Output isn't correct
59 Incorrect 3 ms 23912 KB Output isn't correct
60 Incorrect 6 ms 23896 KB Output isn't correct
61 Correct 3 ms 24084 KB Output is correct
62 Incorrect 3 ms 23900 KB Output isn't correct
63 Incorrect 0 ms 23896 KB Output isn't correct
64 Incorrect 6 ms 23916 KB Output isn't correct
65 Correct 3 ms 24088 KB Output is correct
66 Incorrect 9 ms 23964 KB Output isn't correct
67 Incorrect 3 ms 23896 KB Output isn't correct
68 Incorrect 0 ms 23896 KB Output isn't correct
69 Incorrect 6 ms 23932 KB Output isn't correct
70 Incorrect 3 ms 23992 KB Output isn't correct
71 Incorrect 126 ms 26220 KB Output isn't correct
72 Correct 103 ms 30024 KB Output is correct
73 Incorrect 136 ms 26132 KB Output isn't correct
74 Correct 79 ms 30024 KB Output is correct
75 Incorrect 149 ms 26024 KB Output isn't correct
76 Incorrect 139 ms 26240 KB Output isn't correct
77 Incorrect 59 ms 25552 KB Output isn't correct
78 Incorrect 156 ms 28004 KB Output isn't correct
79 Incorrect 133 ms 26016 KB Output isn't correct
80 Incorrect 133 ms 29164 KB Output isn't correct
81 Incorrect 29 ms 24648 KB Output isn't correct
82 Incorrect 96 ms 25540 KB Output isn't correct
83 Incorrect 153 ms 27476 KB Output isn't correct
84 Incorrect 139 ms 27332 KB Output isn't correct
85 Incorrect 149 ms 28156 KB Output isn't correct
86 Incorrect 123 ms 28100 KB Output isn't correct
87 Incorrect 119 ms 26896 KB Output isn't correct
88 Incorrect 26 ms 24200 KB Output isn't correct
89 Incorrect 86 ms 26200 KB Output isn't correct
90 Incorrect 43 ms 26900 KB Output isn't correct
91 Incorrect 3 ms 24080 KB Output isn't correct
92 Incorrect 53 ms 26896 KB Output isn't correct