Submission #20464

# Submission time Handle Problem Language Result Execution time Memory
20464 2017-02-12T00:13:40 Z 책상다리황새두렁넘기(#60, khsoo01) Can polan into space? (OJUZ11_space) C++11
100 / 100
423 ms 35408 KB
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
const ll inf = 1e18;

ll n, a[200005], b[200005], c[200005], sum[200005];
pair<ll,ll> dt[200005], ans;

vector<ll> ord;
vector<pair<ll,ll> > stk;

struct segtree {
	pair<ll,ll> val[888888];
	ll lazy[888888];
	void init (ll SS, ll SE, ll P) {
		if(SS == SE) {val[P] = {0, SS}; return;}
		ll mid = (SS+SE)/2;
		init(SS, mid, 2*P);
		init(mid+1, SE, 2*P+1);
		val[P] = max(val[2*P], val[2*P+1]);
	}
	void init () {init(1, n, 1);}
	void lazydown (ll P) {
		val[2*P].X += lazy[P];
		lazy[2*P] += lazy[P];
		val[2*P+1].X += lazy[P];
		lazy[2*P+1] += lazy[P];
		lazy[P] = 0;
	}
	void update (ll S, ll E, ll SS, ll SE, ll P, ll V) {
		if(S <= SS && SE <= E) {
			val[P].X += V; lazy[P] += V;
			return;
		}
		if(SE < S || E < SS) return;
		lazydown(P);
		ll mid = (SS+SE)/2;
		update(S, E, SS, mid, 2*P, V);
		update(S, E, mid+1, SE, 2*P+1, V);
		val[P] = max(val[2*P], val[2*P+1]);
	}
	void update (ll S, ll E, ll V) {update(S, E, 1, n, 1, V);}
	pair<ll,ll> query (ll S, ll E, ll SS, ll SE, ll P) {
		if(S <= SS && SE <= E) return val[P];
		if(SE < S || E < SS) return {-inf, -inf};
		lazydown(P);
		ll mid = (SS+SE)/2;
		return max(query(S, E, SS, mid, 2*P),
				   query(S, E, mid+1, SE, 2*P+1));
	}
	pair<ll,ll> query (ll S, ll E) {return query(S, E, 1, n, 1);}
} seg;

int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) {
		scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
		sum[i] = sum[i-1] + b[i];
	}
	seg.init();
	stk.push_back({inf, 0});
	dt[1] = {a[1], 0};
	seg.update(1, 1, dt[1].X);
	for(int i=2;i<=n;i++) {
		pair<ll,ll> tmp = max(seg.query(1, i-2), {sum[i-1], 0});
		dt[i] = {tmp.X + a[i], tmp.Y};
		ll cur = c[i] - b[i], prv = 0;
		seg.update(1, i-1, b[i]);
		while(true) {
			if(stk.back().X <= cur) {
				seg.update(stk.back().Y+1, i-1, stk.back().X - prv);
				prv = stk.back().X;
				stk.pop_back();
			}
			else {
				seg.update(stk.back().Y+1, i-1, cur - prv);
				stk.push_back({cur, i-1});
				break;
			}
		}
		seg.update(i, i, dt[i].X);
	}
	for(int i=1;i<=n;i++) {
		ans = max(ans, {dt[i].X + sum[n] - sum[i], i});
	}
	printf("%lld\n",ans.X);
	for(int i=ans.Y;i;i=dt[i].Y) ord.push_back(i);
	int i;
	for(i=ans.Y;dt[i].Y;i=dt[i].Y) {
		pair<ll, ll> tmp = {-inf, -inf};
		for(int j=dt[i].Y+1;j<i;j++) {
			tmp = max(tmp, {c[j] - b[j], j});
		}
		for(int j=dt[i].Y+1;j<tmp.Y;j++) ord.push_back(j);
		for(int j=i-1;j>=tmp.Y;j--) ord.push_back(j);
	}
	while(--i) ord.push_back(i);
	for(int i=ans.Y+1;i<=n;i++) ord.push_back(i);
	for(int i=0;i<n;i++) printf("%lld ",ord[i]);
}

Compilation message

space.cpp: In function 'int main()':
space.cpp:58:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
                  ^
space.cpp:60:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
                                          ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 32248 KB Output is correct
2 Correct 0 ms 32248 KB Output is correct
3 Correct 0 ms 32248 KB Output is correct
4 Correct 0 ms 32248 KB Output is correct
5 Correct 0 ms 32248 KB Output is correct
6 Correct 3 ms 32248 KB Output is correct
7 Correct 0 ms 32248 KB Output is correct
8 Correct 0 ms 32248 KB Output is correct
9 Correct 0 ms 32248 KB Output is correct
10 Correct 0 ms 32248 KB Output is correct
11 Correct 0 ms 32248 KB Output is correct
12 Correct 0 ms 32248 KB Output is correct
13 Correct 0 ms 32248 KB Output is correct
14 Correct 0 ms 32248 KB Output is correct
15 Correct 3 ms 32248 KB Output is correct
16 Correct 0 ms 32248 KB Output is correct
17 Correct 3 ms 32248 KB Output is correct
18 Correct 0 ms 32248 KB Output is correct
19 Correct 0 ms 32248 KB Output is correct
20 Correct 0 ms 32248 KB Output is correct
21 Correct 0 ms 32248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 32248 KB Output is correct
2 Correct 0 ms 32248 KB Output is correct
3 Correct 0 ms 32248 KB Output is correct
4 Correct 0 ms 32248 KB Output is correct
5 Correct 0 ms 32248 KB Output is correct
6 Correct 3 ms 32248 KB Output is correct
7 Correct 0 ms 32248 KB Output is correct
8 Correct 0 ms 32248 KB Output is correct
9 Correct 0 ms 32248 KB Output is correct
10 Correct 0 ms 32248 KB Output is correct
11 Correct 0 ms 32248 KB Output is correct
12 Correct 0 ms 32248 KB Output is correct
13 Correct 0 ms 32248 KB Output is correct
14 Correct 0 ms 32248 KB Output is correct
15 Correct 3 ms 32248 KB Output is correct
16 Correct 0 ms 32248 KB Output is correct
17 Correct 3 ms 32248 KB Output is correct
18 Correct 0 ms 32248 KB Output is correct
19 Correct 0 ms 32248 KB Output is correct
20 Correct 0 ms 32248 KB Output is correct
21 Correct 0 ms 32248 KB Output is correct
22 Correct 0 ms 32248 KB Output is correct
23 Correct 0 ms 32248 KB Output is correct
24 Correct 0 ms 32248 KB Output is correct
25 Correct 3 ms 32248 KB Output is correct
26 Correct 0 ms 32248 KB Output is correct
27 Correct 0 ms 32248 KB Output is correct
28 Correct 0 ms 32248 KB Output is correct
29 Correct 0 ms 32248 KB Output is correct
30 Correct 3 ms 32248 KB Output is correct
31 Correct 3 ms 32248 KB Output is correct
32 Correct 0 ms 32248 KB Output is correct
33 Correct 0 ms 32248 KB Output is correct
34 Correct 0 ms 32248 KB Output is correct
35 Correct 0 ms 32248 KB Output is correct
36 Correct 3 ms 32248 KB Output is correct
37 Correct 0 ms 32248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 32248 KB Output is correct
2 Correct 0 ms 32248 KB Output is correct
3 Correct 0 ms 32248 KB Output is correct
4 Correct 0 ms 32248 KB Output is correct
5 Correct 0 ms 32248 KB Output is correct
6 Correct 3 ms 32248 KB Output is correct
7 Correct 0 ms 32248 KB Output is correct
8 Correct 0 ms 32248 KB Output is correct
9 Correct 0 ms 32248 KB Output is correct
10 Correct 0 ms 32248 KB Output is correct
11 Correct 0 ms 32248 KB Output is correct
12 Correct 0 ms 32248 KB Output is correct
13 Correct 0 ms 32248 KB Output is correct
14 Correct 0 ms 32248 KB Output is correct
15 Correct 3 ms 32248 KB Output is correct
16 Correct 0 ms 32248 KB Output is correct
17 Correct 3 ms 32248 KB Output is correct
18 Correct 0 ms 32248 KB Output is correct
19 Correct 0 ms 32248 KB Output is correct
20 Correct 0 ms 32248 KB Output is correct
21 Correct 0 ms 32248 KB Output is correct
22 Correct 0 ms 32248 KB Output is correct
23 Correct 0 ms 32248 KB Output is correct
24 Correct 0 ms 32248 KB Output is correct
25 Correct 3 ms 32248 KB Output is correct
26 Correct 0 ms 32248 KB Output is correct
27 Correct 0 ms 32248 KB Output is correct
28 Correct 0 ms 32248 KB Output is correct
29 Correct 0 ms 32248 KB Output is correct
30 Correct 3 ms 32248 KB Output is correct
31 Correct 3 ms 32248 KB Output is correct
32 Correct 0 ms 32248 KB Output is correct
33 Correct 0 ms 32248 KB Output is correct
34 Correct 0 ms 32248 KB Output is correct
35 Correct 0 ms 32248 KB Output is correct
36 Correct 3 ms 32248 KB Output is correct
37 Correct 0 ms 32248 KB Output is correct
38 Correct 0 ms 32248 KB Output is correct
39 Correct 0 ms 32248 KB Output is correct
40 Correct 0 ms 32248 KB Output is correct
41 Correct 0 ms 32248 KB Output is correct
42 Correct 0 ms 32248 KB Output is correct
43 Correct 0 ms 32248 KB Output is correct
44 Correct 6 ms 32248 KB Output is correct
45 Correct 0 ms 32248 KB Output is correct
46 Correct 0 ms 32248 KB Output is correct
47 Correct 0 ms 32248 KB Output is correct
48 Correct 0 ms 32248 KB Output is correct
49 Correct 0 ms 32248 KB Output is correct
50 Correct 3 ms 32248 KB Output is correct
51 Correct 0 ms 32248 KB Output is correct
52 Correct 3 ms 32248 KB Output is correct
53 Correct 3 ms 32248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 32248 KB Output is correct
2 Correct 0 ms 32248 KB Output is correct
3 Correct 0 ms 32248 KB Output is correct
4 Correct 0 ms 32248 KB Output is correct
5 Correct 0 ms 32248 KB Output is correct
6 Correct 3 ms 32248 KB Output is correct
7 Correct 0 ms 32248 KB Output is correct
8 Correct 0 ms 32248 KB Output is correct
9 Correct 0 ms 32248 KB Output is correct
10 Correct 0 ms 32248 KB Output is correct
11 Correct 0 ms 32248 KB Output is correct
12 Correct 0 ms 32248 KB Output is correct
13 Correct 0 ms 32248 KB Output is correct
14 Correct 0 ms 32248 KB Output is correct
15 Correct 3 ms 32248 KB Output is correct
16 Correct 0 ms 32248 KB Output is correct
17 Correct 3 ms 32248 KB Output is correct
18 Correct 0 ms 32248 KB Output is correct
19 Correct 0 ms 32248 KB Output is correct
20 Correct 0 ms 32248 KB Output is correct
21 Correct 0 ms 32248 KB Output is correct
22 Correct 0 ms 32248 KB Output is correct
23 Correct 0 ms 32248 KB Output is correct
24 Correct 0 ms 32248 KB Output is correct
25 Correct 3 ms 32248 KB Output is correct
26 Correct 0 ms 32248 KB Output is correct
27 Correct 0 ms 32248 KB Output is correct
28 Correct 0 ms 32248 KB Output is correct
29 Correct 0 ms 32248 KB Output is correct
30 Correct 3 ms 32248 KB Output is correct
31 Correct 3 ms 32248 KB Output is correct
32 Correct 0 ms 32248 KB Output is correct
33 Correct 0 ms 32248 KB Output is correct
34 Correct 0 ms 32248 KB Output is correct
35 Correct 0 ms 32248 KB Output is correct
36 Correct 3 ms 32248 KB Output is correct
37 Correct 0 ms 32248 KB Output is correct
38 Correct 0 ms 32248 KB Output is correct
39 Correct 0 ms 32248 KB Output is correct
40 Correct 0 ms 32248 KB Output is correct
41 Correct 0 ms 32248 KB Output is correct
42 Correct 0 ms 32248 KB Output is correct
43 Correct 0 ms 32248 KB Output is correct
44 Correct 6 ms 32248 KB Output is correct
45 Correct 0 ms 32248 KB Output is correct
46 Correct 0 ms 32248 KB Output is correct
47 Correct 0 ms 32248 KB Output is correct
48 Correct 0 ms 32248 KB Output is correct
49 Correct 0 ms 32248 KB Output is correct
50 Correct 3 ms 32248 KB Output is correct
51 Correct 0 ms 32248 KB Output is correct
52 Correct 3 ms 32248 KB Output is correct
53 Correct 3 ms 32248 KB Output is correct
54 Correct 6 ms 32248 KB Output is correct
55 Correct 16 ms 32524 KB Output is correct
56 Correct 13 ms 32524 KB Output is correct
57 Correct 16 ms 32524 KB Output is correct
58 Correct 19 ms 32524 KB Output is correct
59 Correct 16 ms 32524 KB Output is correct
60 Correct 13 ms 32524 KB Output is correct
61 Correct 16 ms 32524 KB Output is correct
62 Correct 16 ms 32392 KB Output is correct
63 Correct 0 ms 32248 KB Output is correct
64 Correct 19 ms 32524 KB Output is correct
65 Correct 19 ms 32524 KB Output is correct
66 Correct 19 ms 32524 KB Output is correct
67 Correct 9 ms 32392 KB Output is correct
68 Correct 6 ms 32392 KB Output is correct
69 Correct 13 ms 32524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 32248 KB Output is correct
2 Correct 0 ms 32248 KB Output is correct
3 Correct 0 ms 32248 KB Output is correct
4 Correct 0 ms 32248 KB Output is correct
5 Correct 0 ms 32248 KB Output is correct
6 Correct 3 ms 32248 KB Output is correct
7 Correct 0 ms 32248 KB Output is correct
8 Correct 0 ms 32248 KB Output is correct
9 Correct 0 ms 32248 KB Output is correct
10 Correct 0 ms 32248 KB Output is correct
11 Correct 0 ms 32248 KB Output is correct
12 Correct 0 ms 32248 KB Output is correct
13 Correct 0 ms 32248 KB Output is correct
14 Correct 0 ms 32248 KB Output is correct
15 Correct 3 ms 32248 KB Output is correct
16 Correct 0 ms 32248 KB Output is correct
17 Correct 3 ms 32248 KB Output is correct
18 Correct 0 ms 32248 KB Output is correct
19 Correct 0 ms 32248 KB Output is correct
20 Correct 0 ms 32248 KB Output is correct
21 Correct 0 ms 32248 KB Output is correct
22 Correct 0 ms 32248 KB Output is correct
23 Correct 0 ms 32248 KB Output is correct
24 Correct 0 ms 32248 KB Output is correct
25 Correct 3 ms 32248 KB Output is correct
26 Correct 0 ms 32248 KB Output is correct
27 Correct 0 ms 32248 KB Output is correct
28 Correct 0 ms 32248 KB Output is correct
29 Correct 0 ms 32248 KB Output is correct
30 Correct 3 ms 32248 KB Output is correct
31 Correct 3 ms 32248 KB Output is correct
32 Correct 0 ms 32248 KB Output is correct
33 Correct 0 ms 32248 KB Output is correct
34 Correct 0 ms 32248 KB Output is correct
35 Correct 0 ms 32248 KB Output is correct
36 Correct 3 ms 32248 KB Output is correct
37 Correct 0 ms 32248 KB Output is correct
38 Correct 0 ms 32248 KB Output is correct
39 Correct 0 ms 32248 KB Output is correct
40 Correct 0 ms 32248 KB Output is correct
41 Correct 0 ms 32248 KB Output is correct
42 Correct 0 ms 32248 KB Output is correct
43 Correct 0 ms 32248 KB Output is correct
44 Correct 6 ms 32248 KB Output is correct
45 Correct 0 ms 32248 KB Output is correct
46 Correct 0 ms 32248 KB Output is correct
47 Correct 0 ms 32248 KB Output is correct
48 Correct 0 ms 32248 KB Output is correct
49 Correct 0 ms 32248 KB Output is correct
50 Correct 3 ms 32248 KB Output is correct
51 Correct 0 ms 32248 KB Output is correct
52 Correct 3 ms 32248 KB Output is correct
53 Correct 3 ms 32248 KB Output is correct
54 Correct 6 ms 32248 KB Output is correct
55 Correct 16 ms 32524 KB Output is correct
56 Correct 13 ms 32524 KB Output is correct
57 Correct 16 ms 32524 KB Output is correct
58 Correct 19 ms 32524 KB Output is correct
59 Correct 16 ms 32524 KB Output is correct
60 Correct 13 ms 32524 KB Output is correct
61 Correct 16 ms 32524 KB Output is correct
62 Correct 16 ms 32392 KB Output is correct
63 Correct 0 ms 32248 KB Output is correct
64 Correct 19 ms 32524 KB Output is correct
65 Correct 19 ms 32524 KB Output is correct
66 Correct 19 ms 32524 KB Output is correct
67 Correct 9 ms 32392 KB Output is correct
68 Correct 6 ms 32392 KB Output is correct
69 Correct 13 ms 32524 KB Output is correct
70 Correct 16 ms 32524 KB Output is correct
71 Correct 363 ms 35408 KB Output is correct
72 Correct 319 ms 35408 KB Output is correct
73 Correct 346 ms 35408 KB Output is correct
74 Correct 346 ms 35408 KB Output is correct
75 Correct 369 ms 35408 KB Output is correct
76 Correct 366 ms 35408 KB Output is correct
77 Correct 129 ms 33872 KB Output is correct
78 Correct 363 ms 35408 KB Output is correct
79 Correct 369 ms 35408 KB Output is correct
80 Correct 359 ms 35408 KB Output is correct
81 Correct 69 ms 33104 KB Output is correct
82 Correct 229 ms 35408 KB Output is correct
83 Correct 376 ms 35408 KB Output is correct
84 Correct 423 ms 35408 KB Output is correct
85 Correct 366 ms 35408 KB Output is correct
86 Correct 399 ms 35408 KB Output is correct
87 Correct 366 ms 35408 KB Output is correct
88 Correct 63 ms 32720 KB Output is correct
89 Correct 196 ms 33872 KB Output is correct
90 Correct 156 ms 33872 KB Output is correct
91 Correct 13 ms 32524 KB Output is correct
92 Correct 163 ms 33872 KB Output is correct