Submission #20380

# Submission time Handle Problem Language Result Execution time Memory
20380 2017-02-08T03:10:35 Z Can polan into space? (OJUZ11_space) C++
72 / 100
429 ms 19096 KB
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int N;
const int MAX_N = 200010;

ll a[MAX_N][3],sum[MAX_N][3];

ll dp[MAX_N],path[MAX_N],pick[MAX_N];

void f(int x,vector<int>& s){
	if(x==0)return;
	f(path[x],s);
	s.push_back(x);
}

int main(){
	
	scanf("%d",&N);
	for(int i=1;i<=N;i++){
		for(int j=0;j<3;j++){
			scanf("%lld",&a[i][j]);
			sum[i][j]+=sum[i-1][j]+a[i][j];
		}
	}

	for(int i=1;i<=N;i++){
		dp[i]=sum[i-1][1]+a[i][0];
		ll pmax=a[i-1][2]-a[i-1][1],v=i-1;
		for(int j=i-2;j>0 && j>=i-500;j--){
			if(pmax<a[j+1][2]-a[j+1][1]){
				pmax=a[j+1][2]-a[j+1][1];
				v=j+1;
			}
			if(dp[i]<dp[j]+pmax+sum[i-1][1]-sum[j][1]+a[i][0]){
				dp[i]=dp[j]+pmax+sum[i-1][1]-sum[j][1]+a[i][0];
				pick[i]=v;
				path[i]=j;
			}
		}
	}

	ll ans=0,v;
	for(int i=1;i<=N;i++){
		if(ans<dp[i]+sum[N][1]-sum[i][1]){
			ans=dp[i]+sum[N][1]-sum[i][1];
			v=i;
		}
	}

	printf("%lld\n",ans);

	vector<int> st;
	f(v,st);

	assert(!st.empty());

	for(int i=0;i<st.size();i++){
		printf("%d ",st[i]);
	}

	for(int i=st.front()-1;i>=1;i--)printf("%d ",i);
	for(int i=st.back()+1;i<=N;i++)printf("%d ",i);
	
	for(int i=1;i<st.size();i++){
		for(int j=st[i-1]+1;j<pick[st[i]];j++)printf("%d ",j);
		for(int j=st[i]-1;j>=pick[st[i]];j--)printf("%d ",j);
	}
	puts("");

	return 0;
}

Compilation message

space.cpp: In function 'int main()':
space.cpp:63:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<st.size();i++){
               ^
space.cpp:70:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1;i<st.size();i++){
               ^
space.cpp:24:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
                ^
space.cpp:27:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld",&a[i][j]);
                          ^
space.cpp:59:3: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
  f(v,st);
   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 15240 KB Output is correct
2 Correct 0 ms 15240 KB Output is correct
3 Correct 0 ms 15240 KB Output is correct
4 Correct 0 ms 15240 KB Output is correct
5 Correct 0 ms 15240 KB Output is correct
6 Correct 0 ms 15240 KB Output is correct
7 Correct 0 ms 15240 KB Output is correct
8 Correct 0 ms 15240 KB Output is correct
9 Correct 0 ms 15240 KB Output is correct
10 Correct 0 ms 15240 KB Output is correct
11 Correct 0 ms 15240 KB Output is correct
12 Correct 0 ms 15240 KB Output is correct
13 Correct 0 ms 15240 KB Output is correct
14 Correct 0 ms 15240 KB Output is correct
15 Correct 0 ms 15240 KB Output is correct
16 Correct 0 ms 15240 KB Output is correct
17 Correct 0 ms 15240 KB Output is correct
18 Correct 0 ms 15240 KB Output is correct
19 Correct 0 ms 15240 KB Output is correct
20 Correct 0 ms 15240 KB Output is correct
21 Correct 0 ms 15240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 15240 KB Output is correct
2 Correct 0 ms 15240 KB Output is correct
3 Correct 0 ms 15240 KB Output is correct
4 Correct 0 ms 15240 KB Output is correct
5 Correct 0 ms 15240 KB Output is correct
6 Correct 0 ms 15240 KB Output is correct
7 Correct 0 ms 15240 KB Output is correct
8 Correct 0 ms 15240 KB Output is correct
9 Correct 0 ms 15240 KB Output is correct
10 Correct 0 ms 15240 KB Output is correct
11 Correct 0 ms 15240 KB Output is correct
12 Correct 0 ms 15240 KB Output is correct
13 Correct 0 ms 15240 KB Output is correct
14 Correct 0 ms 15240 KB Output is correct
15 Correct 0 ms 15240 KB Output is correct
16 Correct 0 ms 15240 KB Output is correct
17 Correct 0 ms 15240 KB Output is correct
18 Correct 0 ms 15240 KB Output is correct
19 Correct 0 ms 15240 KB Output is correct
20 Correct 0 ms 15240 KB Output is correct
21 Correct 0 ms 15240 KB Output is correct
22 Correct 0 ms 15240 KB Output is correct
23 Correct 0 ms 15240 KB Output is correct
24 Correct 0 ms 15240 KB Output is correct
25 Correct 0 ms 15240 KB Output is correct
26 Correct 0 ms 15240 KB Output is correct
27 Correct 0 ms 15240 KB Output is correct
28 Correct 0 ms 15240 KB Output is correct
29 Correct 0 ms 15240 KB Output is correct
30 Correct 0 ms 15240 KB Output is correct
31 Correct 0 ms 15240 KB Output is correct
32 Correct 0 ms 15240 KB Output is correct
33 Correct 0 ms 15240 KB Output is correct
34 Correct 0 ms 15240 KB Output is correct
35 Correct 0 ms 15240 KB Output is correct
36 Correct 0 ms 15240 KB Output is correct
37 Correct 0 ms 15240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 15240 KB Output is correct
2 Correct 0 ms 15240 KB Output is correct
3 Correct 0 ms 15240 KB Output is correct
4 Correct 0 ms 15240 KB Output is correct
5 Correct 0 ms 15240 KB Output is correct
6 Correct 0 ms 15240 KB Output is correct
7 Correct 0 ms 15240 KB Output is correct
8 Correct 0 ms 15240 KB Output is correct
9 Correct 0 ms 15240 KB Output is correct
10 Correct 0 ms 15240 KB Output is correct
11 Correct 0 ms 15240 KB Output is correct
12 Correct 0 ms 15240 KB Output is correct
13 Correct 0 ms 15240 KB Output is correct
14 Correct 0 ms 15240 KB Output is correct
15 Correct 0 ms 15240 KB Output is correct
16 Correct 0 ms 15240 KB Output is correct
17 Correct 0 ms 15240 KB Output is correct
18 Correct 0 ms 15240 KB Output is correct
19 Correct 0 ms 15240 KB Output is correct
20 Correct 0 ms 15240 KB Output is correct
21 Correct 0 ms 15240 KB Output is correct
22 Correct 0 ms 15240 KB Output is correct
23 Correct 0 ms 15240 KB Output is correct
24 Correct 0 ms 15240 KB Output is correct
25 Correct 0 ms 15240 KB Output is correct
26 Correct 0 ms 15240 KB Output is correct
27 Correct 0 ms 15240 KB Output is correct
28 Correct 0 ms 15240 KB Output is correct
29 Correct 0 ms 15240 KB Output is correct
30 Correct 0 ms 15240 KB Output is correct
31 Correct 0 ms 15240 KB Output is correct
32 Correct 0 ms 15240 KB Output is correct
33 Correct 0 ms 15240 KB Output is correct
34 Correct 0 ms 15240 KB Output is correct
35 Correct 0 ms 15240 KB Output is correct
36 Correct 0 ms 15240 KB Output is correct
37 Correct 0 ms 15240 KB Output is correct
38 Correct 0 ms 15240 KB Output is correct
39 Correct 0 ms 15240 KB Output is correct
40 Correct 0 ms 15240 KB Output is correct
41 Correct 0 ms 15240 KB Output is correct
42 Correct 0 ms 15240 KB Output is correct
43 Correct 0 ms 15240 KB Output is correct
44 Correct 0 ms 15240 KB Output is correct
45 Correct 0 ms 15240 KB Output is correct
46 Correct 0 ms 15240 KB Output is correct
47 Correct 0 ms 15240 KB Output is correct
48 Correct 0 ms 15240 KB Output is correct
49 Correct 0 ms 15240 KB Output is correct
50 Correct 0 ms 15240 KB Output is correct
51 Correct 0 ms 15240 KB Output is correct
52 Correct 0 ms 15240 KB Output is correct
53 Correct 0 ms 15240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 15240 KB Output is correct
2 Correct 0 ms 15240 KB Output is correct
3 Correct 0 ms 15240 KB Output is correct
4 Correct 0 ms 15240 KB Output is correct
5 Correct 0 ms 15240 KB Output is correct
6 Correct 0 ms 15240 KB Output is correct
7 Correct 0 ms 15240 KB Output is correct
8 Correct 0 ms 15240 KB Output is correct
9 Correct 0 ms 15240 KB Output is correct
10 Correct 0 ms 15240 KB Output is correct
11 Correct 0 ms 15240 KB Output is correct
12 Correct 0 ms 15240 KB Output is correct
13 Correct 0 ms 15240 KB Output is correct
14 Correct 0 ms 15240 KB Output is correct
15 Correct 0 ms 15240 KB Output is correct
16 Correct 0 ms 15240 KB Output is correct
17 Correct 0 ms 15240 KB Output is correct
18 Correct 0 ms 15240 KB Output is correct
19 Correct 0 ms 15240 KB Output is correct
20 Correct 0 ms 15240 KB Output is correct
21 Correct 0 ms 15240 KB Output is correct
22 Correct 0 ms 15240 KB Output is correct
23 Correct 0 ms 15240 KB Output is correct
24 Correct 0 ms 15240 KB Output is correct
25 Correct 0 ms 15240 KB Output is correct
26 Correct 0 ms 15240 KB Output is correct
27 Correct 0 ms 15240 KB Output is correct
28 Correct 0 ms 15240 KB Output is correct
29 Correct 0 ms 15240 KB Output is correct
30 Correct 0 ms 15240 KB Output is correct
31 Correct 0 ms 15240 KB Output is correct
32 Correct 0 ms 15240 KB Output is correct
33 Correct 0 ms 15240 KB Output is correct
34 Correct 0 ms 15240 KB Output is correct
35 Correct 0 ms 15240 KB Output is correct
36 Correct 0 ms 15240 KB Output is correct
37 Correct 0 ms 15240 KB Output is correct
38 Correct 0 ms 15240 KB Output is correct
39 Correct 0 ms 15240 KB Output is correct
40 Correct 0 ms 15240 KB Output is correct
41 Correct 0 ms 15240 KB Output is correct
42 Correct 0 ms 15240 KB Output is correct
43 Correct 0 ms 15240 KB Output is correct
44 Correct 0 ms 15240 KB Output is correct
45 Correct 0 ms 15240 KB Output is correct
46 Correct 0 ms 15240 KB Output is correct
47 Correct 0 ms 15240 KB Output is correct
48 Correct 0 ms 15240 KB Output is correct
49 Correct 0 ms 15240 KB Output is correct
50 Correct 0 ms 15240 KB Output is correct
51 Correct 0 ms 15240 KB Output is correct
52 Correct 0 ms 15240 KB Output is correct
53 Correct 0 ms 15240 KB Output is correct
54 Correct 0 ms 15240 KB Output is correct
55 Correct 16 ms 15240 KB Output is correct
56 Correct 19 ms 15240 KB Output is correct
57 Correct 26 ms 15240 KB Output is correct
58 Correct 19 ms 15240 KB Output is correct
59 Correct 23 ms 15240 KB Output is correct
60 Correct 23 ms 15240 KB Output is correct
61 Correct 16 ms 15240 KB Output is correct
62 Correct 13 ms 15240 KB Output is correct
63 Correct 3 ms 15240 KB Output is correct
64 Correct 16 ms 15240 KB Output is correct
65 Correct 16 ms 15240 KB Output is correct
66 Correct 19 ms 15240 KB Output is correct
67 Correct 9 ms 15240 KB Output is correct
68 Correct 9 ms 15240 KB Output is correct
69 Correct 19 ms 15412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 15240 KB Output is correct
2 Correct 0 ms 15240 KB Output is correct
3 Correct 0 ms 15240 KB Output is correct
4 Correct 0 ms 15240 KB Output is correct
5 Correct 0 ms 15240 KB Output is correct
6 Correct 0 ms 15240 KB Output is correct
7 Correct 0 ms 15240 KB Output is correct
8 Correct 0 ms 15240 KB Output is correct
9 Correct 0 ms 15240 KB Output is correct
10 Correct 0 ms 15240 KB Output is correct
11 Correct 0 ms 15240 KB Output is correct
12 Correct 0 ms 15240 KB Output is correct
13 Correct 0 ms 15240 KB Output is correct
14 Correct 0 ms 15240 KB Output is correct
15 Correct 0 ms 15240 KB Output is correct
16 Correct 0 ms 15240 KB Output is correct
17 Correct 0 ms 15240 KB Output is correct
18 Correct 0 ms 15240 KB Output is correct
19 Correct 0 ms 15240 KB Output is correct
20 Correct 0 ms 15240 KB Output is correct
21 Correct 0 ms 15240 KB Output is correct
22 Correct 0 ms 15240 KB Output is correct
23 Correct 0 ms 15240 KB Output is correct
24 Correct 0 ms 15240 KB Output is correct
25 Correct 0 ms 15240 KB Output is correct
26 Correct 0 ms 15240 KB Output is correct
27 Correct 0 ms 15240 KB Output is correct
28 Correct 0 ms 15240 KB Output is correct
29 Correct 0 ms 15240 KB Output is correct
30 Correct 0 ms 15240 KB Output is correct
31 Correct 0 ms 15240 KB Output is correct
32 Correct 0 ms 15240 KB Output is correct
33 Correct 0 ms 15240 KB Output is correct
34 Correct 0 ms 15240 KB Output is correct
35 Correct 0 ms 15240 KB Output is correct
36 Correct 0 ms 15240 KB Output is correct
37 Correct 0 ms 15240 KB Output is correct
38 Correct 0 ms 15240 KB Output is correct
39 Correct 0 ms 15240 KB Output is correct
40 Correct 0 ms 15240 KB Output is correct
41 Correct 0 ms 15240 KB Output is correct
42 Correct 0 ms 15240 KB Output is correct
43 Correct 0 ms 15240 KB Output is correct
44 Correct 0 ms 15240 KB Output is correct
45 Correct 0 ms 15240 KB Output is correct
46 Correct 0 ms 15240 KB Output is correct
47 Correct 0 ms 15240 KB Output is correct
48 Correct 0 ms 15240 KB Output is correct
49 Correct 0 ms 15240 KB Output is correct
50 Correct 0 ms 15240 KB Output is correct
51 Correct 0 ms 15240 KB Output is correct
52 Correct 0 ms 15240 KB Output is correct
53 Correct 0 ms 15240 KB Output is correct
54 Correct 0 ms 15240 KB Output is correct
55 Correct 16 ms 15240 KB Output is correct
56 Correct 19 ms 15240 KB Output is correct
57 Correct 26 ms 15240 KB Output is correct
58 Correct 19 ms 15240 KB Output is correct
59 Correct 23 ms 15240 KB Output is correct
60 Correct 23 ms 15240 KB Output is correct
61 Correct 16 ms 15240 KB Output is correct
62 Correct 13 ms 15240 KB Output is correct
63 Correct 3 ms 15240 KB Output is correct
64 Correct 16 ms 15240 KB Output is correct
65 Correct 16 ms 15240 KB Output is correct
66 Correct 19 ms 15240 KB Output is correct
67 Correct 9 ms 15240 KB Output is correct
68 Correct 9 ms 15240 KB Output is correct
69 Correct 19 ms 15412 KB Output is correct
70 Correct 19 ms 15240 KB Output is correct
71 Correct 416 ms 17348 KB Output is correct
72 Correct 356 ms 15240 KB Output is correct
73 Correct 406 ms 17348 KB Output is correct
74 Correct 339 ms 15240 KB Output is correct
75 Correct 366 ms 17344 KB Output is correct
76 Correct 376 ms 17348 KB Output is correct
77 Correct 156 ms 16112 KB Output is correct
78 Correct 429 ms 17352 KB Output is correct
79 Correct 376 ms 17344 KB Output is correct
80 Correct 359 ms 15240 KB Output is correct
81 Correct 113 ms 15612 KB Output is correct
82 Correct 256 ms 16776 KB Output is correct
83 Correct 359 ms 17344 KB Output is correct
84 Correct 363 ms 17348 KB Output is correct
85 Correct 376 ms 17344 KB Output is correct
86 Correct 369 ms 17352 KB Output is correct
87 Correct 359 ms 19096 KB Output is correct
88 Correct 66 ms 15540 KB Output is correct
89 Correct 226 ms 16388 KB Output is correct
90 Incorrect 166 ms 15240 KB Output isn't correct
91 Incorrect 16 ms 15240 KB Output isn't correct
92 Incorrect 176 ms 15240 KB Output isn't correct