# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
20342 | 2017-02-07T06:13:33 Z | Can polan into space? (OJUZ11_space) | C++ | 1088 ms | 10548 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--){ 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 308 KB | Output is correct |
2 | Correct | 1 ms | 440 KB | Output is correct |
3 | Correct | 1 ms | 440 KB | Output is correct |
4 | Correct | 1 ms | 440 KB | Output is correct |
5 | Correct | 1 ms | 440 KB | Output is correct |
6 | Correct | 1 ms | 440 KB | Output is correct |
7 | Correct | 1 ms | 440 KB | Output is correct |
8 | Correct | 1 ms | 440 KB | Output is correct |
9 | Correct | 1 ms | 440 KB | Output is correct |
10 | Correct | 1 ms | 440 KB | Output is correct |
11 | Correct | 1 ms | 440 KB | Output is correct |
12 | Correct | 1 ms | 440 KB | Output is correct |
13 | Correct | 1 ms | 440 KB | Output is correct |
14 | Correct | 1 ms | 440 KB | Output is correct |
15 | Correct | 1 ms | 440 KB | Output is correct |
16 | Correct | 1 ms | 440 KB | Output is correct |
17 | Correct | 1 ms | 440 KB | Output is correct |
18 | Correct | 1 ms | 440 KB | Output is correct |
19 | Correct | 1 ms | 440 KB | Output is correct |
20 | Correct | 1 ms | 440 KB | Output is correct |
21 | Correct | 2 ms | 440 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 308 KB | Output is correct |
2 | Correct | 1 ms | 440 KB | Output is correct |
3 | Correct | 1 ms | 440 KB | Output is correct |
4 | Correct | 1 ms | 440 KB | Output is correct |
5 | Correct | 1 ms | 440 KB | Output is correct |
6 | Correct | 1 ms | 440 KB | Output is correct |
7 | Correct | 1 ms | 440 KB | Output is correct |
8 | Correct | 1 ms | 440 KB | Output is correct |
9 | Correct | 1 ms | 440 KB | Output is correct |
10 | Correct | 1 ms | 440 KB | Output is correct |
11 | Correct | 1 ms | 440 KB | Output is correct |
12 | Correct | 1 ms | 440 KB | Output is correct |
13 | Correct | 1 ms | 440 KB | Output is correct |
14 | Correct | 1 ms | 440 KB | Output is correct |
15 | Correct | 1 ms | 440 KB | Output is correct |
16 | Correct | 1 ms | 440 KB | Output is correct |
17 | Correct | 1 ms | 440 KB | Output is correct |
18 | Correct | 1 ms | 440 KB | Output is correct |
19 | Correct | 1 ms | 440 KB | Output is correct |
20 | Correct | 1 ms | 440 KB | Output is correct |
21 | Correct | 2 ms | 440 KB | Output is correct |
22 | Correct | 1 ms | 440 KB | Output is correct |
23 | Correct | 1 ms | 440 KB | Output is correct |
24 | Correct | 1 ms | 440 KB | Output is correct |
25 | Correct | 1 ms | 440 KB | Output is correct |
26 | Correct | 1 ms | 440 KB | Output is correct |
27 | Correct | 1 ms | 440 KB | Output is correct |
28 | Correct | 1 ms | 440 KB | Output is correct |
29 | Correct | 1 ms | 440 KB | Output is correct |
30 | Correct | 1 ms | 440 KB | Output is correct |
31 | Correct | 1 ms | 440 KB | Output is correct |
32 | Correct | 1 ms | 440 KB | Output is correct |
33 | Correct | 1 ms | 440 KB | Output is correct |
34 | Correct | 1 ms | 440 KB | Output is correct |
35 | Correct | 1 ms | 440 KB | Output is correct |
36 | Correct | 1 ms | 440 KB | Output is correct |
37 | Correct | 1 ms | 440 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 308 KB | Output is correct |
2 | Correct | 1 ms | 440 KB | Output is correct |
3 | Correct | 1 ms | 440 KB | Output is correct |
4 | Correct | 1 ms | 440 KB | Output is correct |
5 | Correct | 1 ms | 440 KB | Output is correct |
6 | Correct | 1 ms | 440 KB | Output is correct |
7 | Correct | 1 ms | 440 KB | Output is correct |
8 | Correct | 1 ms | 440 KB | Output is correct |
9 | Correct | 1 ms | 440 KB | Output is correct |
10 | Correct | 1 ms | 440 KB | Output is correct |
11 | Correct | 1 ms | 440 KB | Output is correct |
12 | Correct | 1 ms | 440 KB | Output is correct |
13 | Correct | 1 ms | 440 KB | Output is correct |
14 | Correct | 1 ms | 440 KB | Output is correct |
15 | Correct | 1 ms | 440 KB | Output is correct |
16 | Correct | 1 ms | 440 KB | Output is correct |
17 | Correct | 1 ms | 440 KB | Output is correct |
18 | Correct | 1 ms | 440 KB | Output is correct |
19 | Correct | 1 ms | 440 KB | Output is correct |
20 | Correct | 1 ms | 440 KB | Output is correct |
21 | Correct | 2 ms | 440 KB | Output is correct |
22 | Correct | 1 ms | 440 KB | Output is correct |
23 | Correct | 1 ms | 440 KB | Output is correct |
24 | Correct | 1 ms | 440 KB | Output is correct |
25 | Correct | 1 ms | 440 KB | Output is correct |
26 | Correct | 1 ms | 440 KB | Output is correct |
27 | Correct | 1 ms | 440 KB | Output is correct |
28 | Correct | 1 ms | 440 KB | Output is correct |
29 | Correct | 1 ms | 440 KB | Output is correct |
30 | Correct | 1 ms | 440 KB | Output is correct |
31 | Correct | 1 ms | 440 KB | Output is correct |
32 | Correct | 1 ms | 440 KB | Output is correct |
33 | Correct | 1 ms | 440 KB | Output is correct |
34 | Correct | 1 ms | 440 KB | Output is correct |
35 | Correct | 1 ms | 440 KB | Output is correct |
36 | Correct | 1 ms | 440 KB | Output is correct |
37 | Correct | 1 ms | 440 KB | Output is correct |
38 | Correct | 1 ms | 440 KB | Output is correct |
39 | Correct | 2 ms | 440 KB | Output is correct |
40 | Correct | 1 ms | 440 KB | Output is correct |
41 | Correct | 2 ms | 440 KB | Output is correct |
42 | Correct | 1 ms | 440 KB | Output is correct |
43 | Correct | 2 ms | 440 KB | Output is correct |
44 | Correct | 2 ms | 440 KB | Output is correct |
45 | Correct | 1 ms | 440 KB | Output is correct |
46 | Correct | 2 ms | 440 KB | Output is correct |
47 | Correct | 2 ms | 440 KB | Output is correct |
48 | Correct | 2 ms | 440 KB | Output is correct |
49 | Correct | 2 ms | 440 KB | Output is correct |
50 | Correct | 2 ms | 440 KB | Output is correct |
51 | Correct | 1 ms | 440 KB | Output is correct |
52 | Correct | 1 ms | 440 KB | Output is correct |
53 | Correct | 2 ms | 440 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 308 KB | Output is correct |
2 | Correct | 1 ms | 440 KB | Output is correct |
3 | Correct | 1 ms | 440 KB | Output is correct |
4 | Correct | 1 ms | 440 KB | Output is correct |
5 | Correct | 1 ms | 440 KB | Output is correct |
6 | Correct | 1 ms | 440 KB | Output is correct |
7 | Correct | 1 ms | 440 KB | Output is correct |
8 | Correct | 1 ms | 440 KB | Output is correct |
9 | Correct | 1 ms | 440 KB | Output is correct |
10 | Correct | 1 ms | 440 KB | Output is correct |
11 | Correct | 1 ms | 440 KB | Output is correct |
12 | Correct | 1 ms | 440 KB | Output is correct |
13 | Correct | 1 ms | 440 KB | Output is correct |
14 | Correct | 1 ms | 440 KB | Output is correct |
15 | Correct | 1 ms | 440 KB | Output is correct |
16 | Correct | 1 ms | 440 KB | Output is correct |
17 | Correct | 1 ms | 440 KB | Output is correct |
18 | Correct | 1 ms | 440 KB | Output is correct |
19 | Correct | 1 ms | 440 KB | Output is correct |
20 | Correct | 1 ms | 440 KB | Output is correct |
21 | Correct | 2 ms | 440 KB | Output is correct |
22 | Correct | 1 ms | 440 KB | Output is correct |
23 | Correct | 1 ms | 440 KB | Output is correct |
24 | Correct | 1 ms | 440 KB | Output is correct |
25 | Correct | 1 ms | 440 KB | Output is correct |
26 | Correct | 1 ms | 440 KB | Output is correct |
27 | Correct | 1 ms | 440 KB | Output is correct |
28 | Correct | 1 ms | 440 KB | Output is correct |
29 | Correct | 1 ms | 440 KB | Output is correct |
30 | Correct | 1 ms | 440 KB | Output is correct |
31 | Correct | 1 ms | 440 KB | Output is correct |
32 | Correct | 1 ms | 440 KB | Output is correct |
33 | Correct | 1 ms | 440 KB | Output is correct |
34 | Correct | 1 ms | 440 KB | Output is correct |
35 | Correct | 1 ms | 440 KB | Output is correct |
36 | Correct | 1 ms | 440 KB | Output is correct |
37 | Correct | 1 ms | 440 KB | Output is correct |
38 | Correct | 1 ms | 440 KB | Output is correct |
39 | Correct | 2 ms | 440 KB | Output is correct |
40 | Correct | 1 ms | 440 KB | Output is correct |
41 | Correct | 2 ms | 440 KB | Output is correct |
42 | Correct | 1 ms | 440 KB | Output is correct |
43 | Correct | 2 ms | 440 KB | Output is correct |
44 | Correct | 2 ms | 440 KB | Output is correct |
45 | Correct | 1 ms | 440 KB | Output is correct |
46 | Correct | 2 ms | 440 KB | Output is correct |
47 | Correct | 2 ms | 440 KB | Output is correct |
48 | Correct | 2 ms | 440 KB | Output is correct |
49 | Correct | 2 ms | 440 KB | Output is correct |
50 | Correct | 2 ms | 440 KB | Output is correct |
51 | Correct | 1 ms | 440 KB | Output is correct |
52 | Correct | 1 ms | 440 KB | Output is correct |
53 | Correct | 2 ms | 440 KB | Output is correct |
54 | Correct | 2 ms | 440 KB | Output is correct |
55 | Correct | 123 ms | 1256 KB | Output is correct |
56 | Correct | 124 ms | 1364 KB | Output is correct |
57 | Correct | 123 ms | 1372 KB | Output is correct |
58 | Correct | 125 ms | 1380 KB | Output is correct |
59 | Correct | 125 ms | 1380 KB | Output is correct |
60 | Correct | 130 ms | 1380 KB | Output is correct |
61 | Correct | 124 ms | 1380 KB | Output is correct |
62 | Correct | 67 ms | 1508 KB | Output is correct |
63 | Correct | 7 ms | 1508 KB | Output is correct |
64 | Correct | 126 ms | 1508 KB | Output is correct |
65 | Correct | 124 ms | 1508 KB | Output is correct |
66 | Correct | 132 ms | 1508 KB | Output is correct |
67 | Correct | 33 ms | 1508 KB | Output is correct |
68 | Correct | 15 ms | 1508 KB | Output is correct |
69 | Correct | 124 ms | 1508 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 308 KB | Output is correct |
2 | Correct | 1 ms | 440 KB | Output is correct |
3 | Correct | 1 ms | 440 KB | Output is correct |
4 | Correct | 1 ms | 440 KB | Output is correct |
5 | Correct | 1 ms | 440 KB | Output is correct |
6 | Correct | 1 ms | 440 KB | Output is correct |
7 | Correct | 1 ms | 440 KB | Output is correct |
8 | Correct | 1 ms | 440 KB | Output is correct |
9 | Correct | 1 ms | 440 KB | Output is correct |
10 | Correct | 1 ms | 440 KB | Output is correct |
11 | Correct | 1 ms | 440 KB | Output is correct |
12 | Correct | 1 ms | 440 KB | Output is correct |
13 | Correct | 1 ms | 440 KB | Output is correct |
14 | Correct | 1 ms | 440 KB | Output is correct |
15 | Correct | 1 ms | 440 KB | Output is correct |
16 | Correct | 1 ms | 440 KB | Output is correct |
17 | Correct | 1 ms | 440 KB | Output is correct |
18 | Correct | 1 ms | 440 KB | Output is correct |
19 | Correct | 1 ms | 440 KB | Output is correct |
20 | Correct | 1 ms | 440 KB | Output is correct |
21 | Correct | 2 ms | 440 KB | Output is correct |
22 | Correct | 1 ms | 440 KB | Output is correct |
23 | Correct | 1 ms | 440 KB | Output is correct |
24 | Correct | 1 ms | 440 KB | Output is correct |
25 | Correct | 1 ms | 440 KB | Output is correct |
26 | Correct | 1 ms | 440 KB | Output is correct |
27 | Correct | 1 ms | 440 KB | Output is correct |
28 | Correct | 1 ms | 440 KB | Output is correct |
29 | Correct | 1 ms | 440 KB | Output is correct |
30 | Correct | 1 ms | 440 KB | Output is correct |
31 | Correct | 1 ms | 440 KB | Output is correct |
32 | Correct | 1 ms | 440 KB | Output is correct |
33 | Correct | 1 ms | 440 KB | Output is correct |
34 | Correct | 1 ms | 440 KB | Output is correct |
35 | Correct | 1 ms | 440 KB | Output is correct |
36 | Correct | 1 ms | 440 KB | Output is correct |
37 | Correct | 1 ms | 440 KB | Output is correct |
38 | Correct | 1 ms | 440 KB | Output is correct |
39 | Correct | 2 ms | 440 KB | Output is correct |
40 | Correct | 1 ms | 440 KB | Output is correct |
41 | Correct | 2 ms | 440 KB | Output is correct |
42 | Correct | 1 ms | 440 KB | Output is correct |
43 | Correct | 2 ms | 440 KB | Output is correct |
44 | Correct | 2 ms | 440 KB | Output is correct |
45 | Correct | 1 ms | 440 KB | Output is correct |
46 | Correct | 2 ms | 440 KB | Output is correct |
47 | Correct | 2 ms | 440 KB | Output is correct |
48 | Correct | 2 ms | 440 KB | Output is correct |
49 | Correct | 2 ms | 440 KB | Output is correct |
50 | Correct | 2 ms | 440 KB | Output is correct |
51 | Correct | 1 ms | 440 KB | Output is correct |
52 | Correct | 1 ms | 440 KB | Output is correct |
53 | Correct | 2 ms | 440 KB | Output is correct |
54 | Correct | 2 ms | 440 KB | Output is correct |
55 | Correct | 123 ms | 1256 KB | Output is correct |
56 | Correct | 124 ms | 1364 KB | Output is correct |
57 | Correct | 123 ms | 1372 KB | Output is correct |
58 | Correct | 125 ms | 1380 KB | Output is correct |
59 | Correct | 125 ms | 1380 KB | Output is correct |
60 | Correct | 130 ms | 1380 KB | Output is correct |
61 | Correct | 124 ms | 1380 KB | Output is correct |
62 | Correct | 67 ms | 1508 KB | Output is correct |
63 | Correct | 7 ms | 1508 KB | Output is correct |
64 | Correct | 126 ms | 1508 KB | Output is correct |
65 | Correct | 124 ms | 1508 KB | Output is correct |
66 | Correct | 132 ms | 1508 KB | Output is correct |
67 | Correct | 33 ms | 1508 KB | Output is correct |
68 | Correct | 15 ms | 1508 KB | Output is correct |
69 | Correct | 124 ms | 1508 KB | Output is correct |
70 | Correct | 123 ms | 1508 KB | Output is correct |
71 | Execution timed out | 1087 ms | 10548 KB | Time limit exceeded |
72 | Execution timed out | 1081 ms | 10548 KB | Time limit exceeded |
73 | Execution timed out | 1084 ms | 10548 KB | Time limit exceeded |
74 | Execution timed out | 1086 ms | 10548 KB | Time limit exceeded |
75 | Execution timed out | 1088 ms | 10548 KB | Time limit exceeded |
76 | Execution timed out | 1087 ms | 10548 KB | Time limit exceeded |
77 | Execution timed out | 1083 ms | 10548 KB | Time limit exceeded |
78 | Execution timed out | 1082 ms | 10548 KB | Time limit exceeded |
79 | Execution timed out | 1084 ms | 10548 KB | Time limit exceeded |
80 | Execution timed out | 1088 ms | 10548 KB | Time limit exceeded |
81 | Execution timed out | 1081 ms | 10548 KB | Time limit exceeded |
82 | Execution timed out | 1086 ms | 10548 KB | Time limit exceeded |
83 | Execution timed out | 1087 ms | 10548 KB | Time limit exceeded |
84 | Execution timed out | 1083 ms | 10548 KB | Time limit exceeded |
85 | Execution timed out | 1083 ms | 10548 KB | Time limit exceeded |
86 | Execution timed out | 1082 ms | 10548 KB | Time limit exceeded |
87 | Execution timed out | 1087 ms | 10548 KB | Time limit exceeded |
88 | Execution timed out | 1082 ms | 10548 KB | Time limit exceeded |
89 | Execution timed out | 1082 ms | 10548 KB | Time limit exceeded |
90 | Execution timed out | 1084 ms | 10548 KB | Time limit exceeded |
91 | Correct | 121 ms | 10548 KB | Output is correct |
92 | Execution timed out | 1087 ms | 10548 KB | Time limit exceeded |