Submission #36042

# Submission time Handle Problem Language Result Execution time Memory
36042 2017-12-04T14:41:04 Z cheater2k Bulldozer (JOI17_bulldozer) C++14
100 / 100
1074 ms 32536 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2005;
const long long inf = 1e18;

struct SegmentTree {
	struct Node {
		long long val; long long pre; long long suf; long long sum;
		Node() { val = -inf; sum = pre = suf = 0; }
	} it[N << 2];

	#define mid ((l + r) >> 1)
	Node merge(Node le, Node ri) {
		Node cur = Node();
		cur.sum = le.sum + ri.sum;
		cur.val = max({le.val, ri.val, le.suf + ri.pre});
		cur.pre = max(le.pre, le.sum + ri.pre);
		cur.suf = max(ri.suf, ri.sum + le.suf);
		return cur;
	}
	void upd(int v, int l, int r, int pos, int val) {
		if (l > r || l > pos || r < pos) return;
		if (l == r) { it[v].val = it[v].pre = it[v].suf = it[v].sum = val; return; }
		upd(v << 1, l, mid, pos, val); upd(v << 1 | 1, mid + 1, r, pos, val);
		it[v] = merge(it[v << 1], it[v << 1 | 1]);
	}
	long long get() { return it[1].val; }
	#undef mid
} seg;

struct Point {
	int x; int y; int w;
	Point(int x=0, int y=0, int w=0): x(x), y(y), w(w) {}
	bool operator < (const Point &rhs) const {
		return y < rhs.y || (y == rhs.y && x < rhs.x);
	}
	Point operator - (Point q) { Point p = *this; return Point(p.x - q.x, p.y - q.y); }
} a[N];

long long cross(Point a, Point b) {
	return 1LL * a.x * b.y - 1LL * a.y * b.x;
}

long long cmp(pair<int,int> p, pair<int,int> q) {
	long long flag = cross(a[p.second] - a[p.first], a[q.second] - a[q.first]);
	return flag;
}

int n;
vector< pair<int,int> > vec;
long long ans;
int pos[N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i].x >> a[i].y >> a[i].w;
	sort(a + 1, a + n + 1);	
	for (int i = 1; i < n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			vec.push_back(make_pair(i,j));
		}
	}
	sort(vec.begin(), vec.end(), [&](pair<int,int> p, pair<int,int> q) {
		long long flag = cmp(p, q);
		if (flag != 0) return flag > 0; else return make_pair(a[p.first], a[p.second]) < make_pair(a[q.first], a[q.second]);
	});

	for (int i = 1; i <= n; ++i) pos[i] = i;
	for (int i = 1; i <= n; ++i) seg.upd(1, 1, n, i, a[i].w);
	ans = max(ans, seg.get());

	for (int i = 0; i < vec.size(); ++i) {
		vector< pair<int,int> > Q;
		Q.push_back(vec[i]);
		while(i + 1 < vec.size() && cmp(vec[i], vec[i+1]) == 0) {
			Q.push_back(vec[i+1]); ++i;
		}
		for (auto p : Q) {
			swap(pos[p.first], pos[p.second]);
			seg.upd(1, 1, n, pos[p.first], a[p.first].w);
			seg.upd(1, 1, n, pos[p.second], a[p.second].w);
		}
		ans = max(ans, seg.get());
	}
	cout << ans << endl;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:74:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < vec.size(); ++i) {
                  ~~^~~~~~~~~~~~
bulldozer.cpp:77:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(i + 1 < vec.size() && cmp(vec[i], vec[i+1]) == 0) {
         ~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 2 ms 768 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 3 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 768 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 4 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 4 ms 740 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 2 ms 640 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 4 ms 768 KB Output is correct
23 Correct 3 ms 768 KB Output is correct
24 Correct 4 ms 768 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 4 ms 740 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 4 ms 768 KB Output is correct
29 Correct 4 ms 768 KB Output is correct
30 Correct 4 ms 768 KB Output is correct
31 Correct 4 ms 684 KB Output is correct
32 Correct 4 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 768 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 4 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 4 ms 740 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 2 ms 640 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 4 ms 768 KB Output is correct
23 Correct 3 ms 768 KB Output is correct
24 Correct 4 ms 768 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 4 ms 740 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 4 ms 768 KB Output is correct
29 Correct 4 ms 768 KB Output is correct
30 Correct 4 ms 768 KB Output is correct
31 Correct 4 ms 684 KB Output is correct
32 Correct 4 ms 768 KB Output is correct
33 Correct 1074 ms 17132 KB Output is correct
34 Correct 1002 ms 17132 KB Output is correct
35 Correct 1030 ms 17216 KB Output is correct
36 Correct 1012 ms 17120 KB Output is correct
37 Correct 1028 ms 17220 KB Output is correct
38 Correct 1039 ms 17120 KB Output is correct
39 Correct 995 ms 17124 KB Output is correct
40 Correct 1040 ms 17132 KB Output is correct
41 Correct 997 ms 17180 KB Output is correct
42 Correct 1000 ms 17132 KB Output is correct
43 Correct 992 ms 17120 KB Output is correct
44 Correct 983 ms 17220 KB Output is correct
45 Correct 1059 ms 17132 KB Output is correct
46 Correct 987 ms 17132 KB Output is correct
47 Correct 1000 ms 17248 KB Output is correct
48 Correct 1061 ms 17136 KB Output is correct
49 Correct 1016 ms 17124 KB Output is correct
50 Correct 1045 ms 17260 KB Output is correct
51 Correct 1006 ms 17232 KB Output is correct
52 Correct 987 ms 17132 KB Output is correct
53 Correct 989 ms 17220 KB Output is correct
54 Correct 999 ms 17132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 768 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 4 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 4 ms 740 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 2 ms 640 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 4 ms 768 KB Output is correct
23 Correct 3 ms 768 KB Output is correct
24 Correct 4 ms 768 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 4 ms 740 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 4 ms 768 KB Output is correct
29 Correct 4 ms 768 KB Output is correct
30 Correct 4 ms 768 KB Output is correct
31 Correct 4 ms 684 KB Output is correct
32 Correct 4 ms 768 KB Output is correct
33 Correct 1074 ms 17132 KB Output is correct
34 Correct 1002 ms 17132 KB Output is correct
35 Correct 1030 ms 17216 KB Output is correct
36 Correct 1012 ms 17120 KB Output is correct
37 Correct 1028 ms 17220 KB Output is correct
38 Correct 1039 ms 17120 KB Output is correct
39 Correct 995 ms 17124 KB Output is correct
40 Correct 1040 ms 17132 KB Output is correct
41 Correct 997 ms 17180 KB Output is correct
42 Correct 1000 ms 17132 KB Output is correct
43 Correct 992 ms 17120 KB Output is correct
44 Correct 983 ms 17220 KB Output is correct
45 Correct 1059 ms 17132 KB Output is correct
46 Correct 987 ms 17132 KB Output is correct
47 Correct 1000 ms 17248 KB Output is correct
48 Correct 1061 ms 17136 KB Output is correct
49 Correct 1016 ms 17124 KB Output is correct
50 Correct 1045 ms 17260 KB Output is correct
51 Correct 1006 ms 17232 KB Output is correct
52 Correct 987 ms 17132 KB Output is correct
53 Correct 989 ms 17220 KB Output is correct
54 Correct 999 ms 17132 KB Output is correct
55 Correct 997 ms 17176 KB Output is correct
56 Correct 1014 ms 17192 KB Output is correct
57 Correct 1012 ms 17132 KB Output is correct
58 Correct 1042 ms 17260 KB Output is correct
59 Correct 1052 ms 17132 KB Output is correct
60 Correct 1037 ms 17232 KB Output is correct
61 Correct 1054 ms 17124 KB Output is correct
62 Correct 1025 ms 17244 KB Output is correct
63 Correct 1036 ms 17132 KB Output is correct
64 Correct 1010 ms 17236 KB Output is correct
65 Correct 1002 ms 17164 KB Output is correct
66 Correct 1042 ms 17224 KB Output is correct
67 Correct 1010 ms 17260 KB Output is correct
68 Correct 996 ms 17132 KB Output is correct
69 Correct 995 ms 17260 KB Output is correct
70 Correct 997 ms 17272 KB Output is correct
71 Correct 999 ms 17120 KB Output is correct
72 Correct 1006 ms 17248 KB Output is correct
73 Correct 1000 ms 17132 KB Output is correct
74 Correct 1022 ms 17252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 2 ms 768 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 3 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 3 ms 640 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 4 ms 768 KB Output is correct
19 Correct 3 ms 768 KB Output is correct
20 Correct 4 ms 768 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 4 ms 768 KB Output is correct
23 Correct 5 ms 768 KB Output is correct
24 Correct 4 ms 768 KB Output is correct
25 Correct 4 ms 740 KB Output is correct
26 Correct 2 ms 640 KB Output is correct
27 Correct 2 ms 640 KB Output is correct
28 Correct 2 ms 640 KB Output is correct
29 Correct 2 ms 640 KB Output is correct
30 Correct 2 ms 640 KB Output is correct
31 Correct 2 ms 640 KB Output is correct
32 Correct 2 ms 640 KB Output is correct
33 Correct 2 ms 640 KB Output is correct
34 Correct 2 ms 640 KB Output is correct
35 Correct 2 ms 640 KB Output is correct
36 Correct 4 ms 768 KB Output is correct
37 Correct 4 ms 768 KB Output is correct
38 Correct 3 ms 768 KB Output is correct
39 Correct 4 ms 768 KB Output is correct
40 Correct 4 ms 768 KB Output is correct
41 Correct 4 ms 740 KB Output is correct
42 Correct 4 ms 768 KB Output is correct
43 Correct 4 ms 768 KB Output is correct
44 Correct 4 ms 768 KB Output is correct
45 Correct 4 ms 768 KB Output is correct
46 Correct 4 ms 684 KB Output is correct
47 Correct 4 ms 768 KB Output is correct
48 Correct 1074 ms 17132 KB Output is correct
49 Correct 1002 ms 17132 KB Output is correct
50 Correct 1030 ms 17216 KB Output is correct
51 Correct 1012 ms 17120 KB Output is correct
52 Correct 1028 ms 17220 KB Output is correct
53 Correct 1039 ms 17120 KB Output is correct
54 Correct 995 ms 17124 KB Output is correct
55 Correct 1040 ms 17132 KB Output is correct
56 Correct 997 ms 17180 KB Output is correct
57 Correct 1000 ms 17132 KB Output is correct
58 Correct 992 ms 17120 KB Output is correct
59 Correct 983 ms 17220 KB Output is correct
60 Correct 1059 ms 17132 KB Output is correct
61 Correct 987 ms 17132 KB Output is correct
62 Correct 1000 ms 17248 KB Output is correct
63 Correct 1061 ms 17136 KB Output is correct
64 Correct 1016 ms 17124 KB Output is correct
65 Correct 1045 ms 17260 KB Output is correct
66 Correct 1006 ms 17232 KB Output is correct
67 Correct 987 ms 17132 KB Output is correct
68 Correct 989 ms 17220 KB Output is correct
69 Correct 999 ms 17132 KB Output is correct
70 Correct 997 ms 17176 KB Output is correct
71 Correct 1014 ms 17192 KB Output is correct
72 Correct 1012 ms 17132 KB Output is correct
73 Correct 1042 ms 17260 KB Output is correct
74 Correct 1052 ms 17132 KB Output is correct
75 Correct 1037 ms 17232 KB Output is correct
76 Correct 1054 ms 17124 KB Output is correct
77 Correct 1025 ms 17244 KB Output is correct
78 Correct 1036 ms 17132 KB Output is correct
79 Correct 1010 ms 17236 KB Output is correct
80 Correct 1002 ms 17164 KB Output is correct
81 Correct 1042 ms 17224 KB Output is correct
82 Correct 1010 ms 17260 KB Output is correct
83 Correct 996 ms 17132 KB Output is correct
84 Correct 995 ms 17260 KB Output is correct
85 Correct 997 ms 17272 KB Output is correct
86 Correct 999 ms 17120 KB Output is correct
87 Correct 1006 ms 17248 KB Output is correct
88 Correct 1000 ms 17132 KB Output is correct
89 Correct 1022 ms 17252 KB Output is correct
90 Correct 1014 ms 17132 KB Output is correct
91 Correct 989 ms 17132 KB Output is correct
92 Correct 993 ms 17248 KB Output is correct
93 Correct 1028 ms 17124 KB Output is correct
94 Correct 1038 ms 17124 KB Output is correct
95 Correct 1037 ms 17132 KB Output is correct
96 Correct 1039 ms 17124 KB Output is correct
97 Correct 1025 ms 17124 KB Output is correct
98 Correct 1034 ms 17252 KB Output is correct
99 Correct 1039 ms 17124 KB Output is correct
100 Correct 907 ms 32536 KB Output is correct
101 Correct 939 ms 32320 KB Output is correct
102 Correct 882 ms 32440 KB Output is correct
103 Correct 866 ms 32360 KB Output is correct
104 Correct 897 ms 32448 KB Output is correct
105 Correct 937 ms 29632 KB Output is correct
106 Correct 943 ms 29764 KB Output is correct
107 Correct 982 ms 29616 KB Output is correct
108 Correct 941 ms 29756 KB Output is correct
109 Correct 934 ms 29632 KB Output is correct
110 Correct 892 ms 17116 KB Output is correct
111 Correct 894 ms 17132 KB Output is correct
112 Correct 915 ms 17220 KB Output is correct
113 Correct 906 ms 17124 KB Output is correct
114 Correct 901 ms 17120 KB Output is correct
115 Correct 905 ms 17124 KB Output is correct
116 Correct 906 ms 17160 KB Output is correct
117 Correct 909 ms 17124 KB Output is correct
118 Correct 892 ms 17172 KB Output is correct
119 Correct 908 ms 17248 KB Output is correct
120 Correct 2 ms 640 KB Output is correct
121 Correct 3 ms 640 KB Output is correct
122 Correct 1006 ms 17156 KB Output is correct
123 Correct 1008 ms 17124 KB Output is correct
124 Correct 989 ms 17124 KB Output is correct
125 Correct 1002 ms 17224 KB Output is correct
126 Correct 1010 ms 17128 KB Output is correct
127 Correct 997 ms 17132 KB Output is correct
128 Correct 1000 ms 17132 KB Output is correct
129 Correct 1022 ms 17132 KB Output is correct
130 Correct 992 ms 17132 KB Output is correct
131 Correct 1004 ms 17132 KB Output is correct
132 Correct 1002 ms 17132 KB Output is correct
133 Correct 992 ms 17124 KB Output is correct