Submission #122687

# Submission time Handle Problem Language Result Execution time Memory
122687 2019-06-29T06:44:06 Z 김세빈(#2998) Bulldozer (JOI17_bulldozer) C++14
100 / 100
1091 ms 64088 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;

struct point{
	ll x, y, c;
	point() {}
	point(ll x, ll y, ll c) : x(x), y(y), c(c) {}
};

struct node{
	ll mv, lv, rv, s;
	
	node() {}
	node(ll v) { s = v; mv = lv = rv = max(0ll, v); }
	
	node operator+ (node &n)
	{
		node ret;
		
		ret.s = s + n.s;
		ret.lv = max(lv, s + n.lv);
		ret.rv = max(n.rv, n.s + rv);
		ret.mv = max(max(mv, n.mv), rv + n.lv);
		
		return ret;
	}
};

node T[5050];
vector <point> P;
vector <pll> V;
ll K[2020];
ll sz = 1 << 11;
ll n, ans;

ll cross(pll va, pll vb)
{
	va = pll(P[va.second].x - P[va.first].x, P[va.second].y - P[va.first].y);
	vb = pll(P[vb.second].x - P[vb.first].x, P[vb.second].y - P[vb.first].y);
	return va.first * vb.second - vb.first * va.second;
}

void insert(ll p, ll v)
{
	p += sz; T[p] = node(v);
	
	for(p>>=1; p; p>>=1){
		T[p] = T[p << 1] + T[p << 1 | 1];
	}
}

ll get(ll l, ll r)
{
	node ls(0), rs(0);
	
	l += sz; r += sz;
	
	for(; l<=r; ){
		if(l & 1) ls = ls + T[l];
		if(~r & 1) rs = T[r] + rs;
		l = l + 1 >> 1;
		r = r - 1 >> 1;
	}
	
	return (ls + rs).mv;
}

int main()
{
	vector <ll> X;
	ll i, j, x, y, c;
	
	scanf("%lld", &n);
	
	for(i=0; i<n; i++){
		scanf("%lld%lld%lld", &x, &y, &c);
		P.emplace_back(x, y, c);
	}
	
	sort(P.begin(), P.end(), [&](point &pa, point &pb){
		if(pa.x != pb.x) return pa.x < pb.x;
		else return pa.y > pb.y;
	});
	
	for(i=0; i<n; i++){	
		K[i] = i;
		for(j=i+1; j<n; j++){
			V.emplace_back(i, j);
		}
	}
	
	sort(V.begin(), V.end(), [&](pll &va, pll &vb){
		return cross(va, vb) > 0;
	});
	
	for(i=0; i<n; i++){
		T[i + sz] = node(P[i].c);
	}
	
	for(i=sz-1; i; i--){
		T[i] = T[i << 1] + T[i << 1 | 1];
	}
	
	ans = get(0, n - 1);
	
	for(i=0; i<V.size(); i=j){
		X.clear();
		
		for(j=i; j<V.size() && cross(V[j], V[i]) == 0; j++){
			X.push_back(V[j].first); X.push_back(V[j].second);
			K[V[j].first] ++; K[V[j].second] --;
		}
		
		sort(X.begin(), X.end());
		X.erase(unique(X.begin(), X.end()), X.end());
		
		for(ll &x: X) insert(K[x], P[x].c);
		
		ans = max(ans, get(0, n - 1));
	}
	
	printf("%lld\n", ans);
	
	return 0;
}

Compilation message

bulldozer.cpp: In function 'll get(ll, ll)':
bulldozer.cpp:65:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   l = l + 1 >> 1;
       ~~^~~
bulldozer.cpp:66:9: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   r = r - 1 >> 1;
       ~~^~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:110:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0; i<V.size(); i=j){
           ~^~~~~~~~~
bulldozer.cpp:113:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=i; j<V.size() && cross(V[j], V[i]) == 0; j++){
            ~^~~~~~~~~
bulldozer.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
bulldozer.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &x, &y, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 3 ms 628 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 660 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 4 ms 632 KB Output is correct
23 Correct 4 ms 636 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
25 Correct 4 ms 632 KB Output is correct
26 Correct 4 ms 632 KB Output is correct
27 Correct 4 ms 636 KB Output is correct
28 Correct 4 ms 632 KB Output is correct
29 Correct 4 ms 632 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 660 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 4 ms 632 KB Output is correct
23 Correct 4 ms 636 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
25 Correct 4 ms 632 KB Output is correct
26 Correct 4 ms 632 KB Output is correct
27 Correct 4 ms 636 KB Output is correct
28 Correct 4 ms 632 KB Output is correct
29 Correct 4 ms 632 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 632 KB Output is correct
33 Correct 1080 ms 33412 KB Output is correct
34 Correct 1058 ms 33340 KB Output is correct
35 Correct 1025 ms 33340 KB Output is correct
36 Correct 1020 ms 33472 KB Output is correct
37 Correct 1040 ms 33340 KB Output is correct
38 Correct 1008 ms 33340 KB Output is correct
39 Correct 1035 ms 33340 KB Output is correct
40 Correct 1024 ms 33340 KB Output is correct
41 Correct 1040 ms 33468 KB Output is correct
42 Correct 1020 ms 33340 KB Output is correct
43 Correct 1068 ms 33340 KB Output is correct
44 Correct 1002 ms 33340 KB Output is correct
45 Correct 1006 ms 33340 KB Output is correct
46 Correct 1041 ms 33360 KB Output is correct
47 Correct 1018 ms 33340 KB Output is correct
48 Correct 1016 ms 33340 KB Output is correct
49 Correct 1010 ms 33340 KB Output is correct
50 Correct 1035 ms 33340 KB Output is correct
51 Correct 1008 ms 33340 KB Output is correct
52 Correct 1038 ms 33340 KB Output is correct
53 Correct 1035 ms 33340 KB Output is correct
54 Correct 1004 ms 33340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 660 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 4 ms 632 KB Output is correct
23 Correct 4 ms 636 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
25 Correct 4 ms 632 KB Output is correct
26 Correct 4 ms 632 KB Output is correct
27 Correct 4 ms 636 KB Output is correct
28 Correct 4 ms 632 KB Output is correct
29 Correct 4 ms 632 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 632 KB Output is correct
33 Correct 1080 ms 33412 KB Output is correct
34 Correct 1058 ms 33340 KB Output is correct
35 Correct 1025 ms 33340 KB Output is correct
36 Correct 1020 ms 33472 KB Output is correct
37 Correct 1040 ms 33340 KB Output is correct
38 Correct 1008 ms 33340 KB Output is correct
39 Correct 1035 ms 33340 KB Output is correct
40 Correct 1024 ms 33340 KB Output is correct
41 Correct 1040 ms 33468 KB Output is correct
42 Correct 1020 ms 33340 KB Output is correct
43 Correct 1068 ms 33340 KB Output is correct
44 Correct 1002 ms 33340 KB Output is correct
45 Correct 1006 ms 33340 KB Output is correct
46 Correct 1041 ms 33360 KB Output is correct
47 Correct 1018 ms 33340 KB Output is correct
48 Correct 1016 ms 33340 KB Output is correct
49 Correct 1010 ms 33340 KB Output is correct
50 Correct 1035 ms 33340 KB Output is correct
51 Correct 1008 ms 33340 KB Output is correct
52 Correct 1038 ms 33340 KB Output is correct
53 Correct 1035 ms 33340 KB Output is correct
54 Correct 1004 ms 33340 KB Output is correct
55 Correct 1010 ms 33340 KB Output is correct
56 Correct 1020 ms 33340 KB Output is correct
57 Correct 1056 ms 33340 KB Output is correct
58 Correct 1030 ms 33340 KB Output is correct
59 Correct 1041 ms 33340 KB Output is correct
60 Correct 1018 ms 33344 KB Output is correct
61 Correct 1022 ms 33340 KB Output is correct
62 Correct 1091 ms 33340 KB Output is correct
63 Correct 1018 ms 33340 KB Output is correct
64 Correct 1037 ms 33344 KB Output is correct
65 Correct 1006 ms 33340 KB Output is correct
66 Correct 1018 ms 33348 KB Output is correct
67 Correct 1037 ms 33340 KB Output is correct
68 Correct 1047 ms 33344 KB Output is correct
69 Correct 1032 ms 33340 KB Output is correct
70 Correct 1016 ms 33340 KB Output is correct
71 Correct 1010 ms 33340 KB Output is correct
72 Correct 1038 ms 33340 KB Output is correct
73 Correct 1020 ms 33340 KB Output is correct
74 Correct 1018 ms 33468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 3 ms 628 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 4 ms 660 KB Output is correct
17 Correct 4 ms 632 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 4 ms 632 KB Output is correct
20 Correct 4 ms 632 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 4 ms 632 KB Output is correct
23 Correct 4 ms 632 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
25 Correct 4 ms 632 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 4 ms 632 KB Output is correct
37 Correct 4 ms 632 KB Output is correct
38 Correct 4 ms 636 KB Output is correct
39 Correct 4 ms 632 KB Output is correct
40 Correct 4 ms 632 KB Output is correct
41 Correct 4 ms 632 KB Output is correct
42 Correct 4 ms 636 KB Output is correct
43 Correct 4 ms 632 KB Output is correct
44 Correct 4 ms 632 KB Output is correct
45 Correct 4 ms 632 KB Output is correct
46 Correct 4 ms 632 KB Output is correct
47 Correct 4 ms 632 KB Output is correct
48 Correct 1080 ms 33412 KB Output is correct
49 Correct 1058 ms 33340 KB Output is correct
50 Correct 1025 ms 33340 KB Output is correct
51 Correct 1020 ms 33472 KB Output is correct
52 Correct 1040 ms 33340 KB Output is correct
53 Correct 1008 ms 33340 KB Output is correct
54 Correct 1035 ms 33340 KB Output is correct
55 Correct 1024 ms 33340 KB Output is correct
56 Correct 1040 ms 33468 KB Output is correct
57 Correct 1020 ms 33340 KB Output is correct
58 Correct 1068 ms 33340 KB Output is correct
59 Correct 1002 ms 33340 KB Output is correct
60 Correct 1006 ms 33340 KB Output is correct
61 Correct 1041 ms 33360 KB Output is correct
62 Correct 1018 ms 33340 KB Output is correct
63 Correct 1016 ms 33340 KB Output is correct
64 Correct 1010 ms 33340 KB Output is correct
65 Correct 1035 ms 33340 KB Output is correct
66 Correct 1008 ms 33340 KB Output is correct
67 Correct 1038 ms 33340 KB Output is correct
68 Correct 1035 ms 33340 KB Output is correct
69 Correct 1004 ms 33340 KB Output is correct
70 Correct 1010 ms 33340 KB Output is correct
71 Correct 1020 ms 33340 KB Output is correct
72 Correct 1056 ms 33340 KB Output is correct
73 Correct 1030 ms 33340 KB Output is correct
74 Correct 1041 ms 33340 KB Output is correct
75 Correct 1018 ms 33344 KB Output is correct
76 Correct 1022 ms 33340 KB Output is correct
77 Correct 1091 ms 33340 KB Output is correct
78 Correct 1018 ms 33340 KB Output is correct
79 Correct 1037 ms 33344 KB Output is correct
80 Correct 1006 ms 33340 KB Output is correct
81 Correct 1018 ms 33348 KB Output is correct
82 Correct 1037 ms 33340 KB Output is correct
83 Correct 1047 ms 33344 KB Output is correct
84 Correct 1032 ms 33340 KB Output is correct
85 Correct 1016 ms 33340 KB Output is correct
86 Correct 1010 ms 33340 KB Output is correct
87 Correct 1038 ms 33340 KB Output is correct
88 Correct 1020 ms 33340 KB Output is correct
89 Correct 1018 ms 33468 KB Output is correct
90 Correct 1033 ms 33328 KB Output is correct
91 Correct 1038 ms 33468 KB Output is correct
92 Correct 1036 ms 33340 KB Output is correct
93 Correct 1036 ms 33340 KB Output is correct
94 Correct 1043 ms 33340 KB Output is correct
95 Correct 1025 ms 33340 KB Output is correct
96 Correct 1024 ms 33340 KB Output is correct
97 Correct 1024 ms 33340 KB Output is correct
98 Correct 1043 ms 33312 KB Output is correct
99 Correct 1042 ms 33340 KB Output is correct
100 Correct 703 ms 63996 KB Output is correct
101 Correct 708 ms 63896 KB Output is correct
102 Correct 699 ms 64088 KB Output is correct
103 Correct 702 ms 64000 KB Output is correct
104 Correct 697 ms 63860 KB Output is correct
105 Correct 807 ms 58648 KB Output is correct
106 Correct 780 ms 58776 KB Output is correct
107 Correct 788 ms 58776 KB Output is correct
108 Correct 788 ms 58708 KB Output is correct
109 Correct 789 ms 58904 KB Output is correct
110 Correct 851 ms 33340 KB Output is correct
111 Correct 874 ms 33340 KB Output is correct
112 Correct 866 ms 33340 KB Output is correct
113 Correct 864 ms 33388 KB Output is correct
114 Correct 859 ms 33324 KB Output is correct
115 Correct 864 ms 33312 KB Output is correct
116 Correct 863 ms 33292 KB Output is correct
117 Correct 861 ms 33340 KB Output is correct
118 Correct 870 ms 33344 KB Output is correct
119 Correct 849 ms 33340 KB Output is correct
120 Correct 2 ms 376 KB Output is correct
121 Correct 2 ms 376 KB Output is correct
122 Correct 1020 ms 33340 KB Output is correct
123 Correct 1008 ms 33340 KB Output is correct
124 Correct 1020 ms 33468 KB Output is correct
125 Correct 1047 ms 33340 KB Output is correct
126 Correct 1026 ms 33340 KB Output is correct
127 Correct 1014 ms 33340 KB Output is correct
128 Correct 1016 ms 33340 KB Output is correct
129 Correct 1016 ms 33344 KB Output is correct
130 Correct 1032 ms 33340 KB Output is correct
131 Correct 1032 ms 33464 KB Output is correct
132 Correct 1037 ms 33340 KB Output is correct
133 Correct 1006 ms 33340 KB Output is correct