답안 #593912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
593912 2022-07-11T17:27:27 Z GusterGoose27 Bulldozer (JOI17_bulldozer) C++11
5 / 100
5 ms 640 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ld, int> pdi;

class Point {
public:
	int x;
	int y;
	int v;
	Point() {}
	Point(int xn, int yn, int vn) {
		x = xn;
		y = yn;
		v = vn;
	}
};

bool operator<(const Point &a, const Point &b) {
	return (a.x == b.x) ? (a.y < b.y) : (a.x < b.x);
}

const int MAXN = 2000;
const ld ERROR = 1e-9;
Point points[MAXN];
int curpos[MAXN];
pdi updates[MAXN*(MAXN-1)];
int t = 0;
int n;

ld get_ang(int i, int j) { // actually the slope but who cares
	return ((ld)points[j].y-points[i].y)/(points[j].x-points[i].x);
}

class STree {
public:
	int n;
	ll *sum;
	ll *max_pre;
	ll *max_suf;
	ll *max_cont;
	STree(int nn) {
		n = pow(2, ceil(log2(nn)));
		sum = new ll[2*n];
		max_pre = new ll[2*n];
		max_suf = new ll[2*n];
		max_cont = new ll[2*n];
		for (int i = 0; i < n; i++) {
			if (i < nn) {
				sum[i+n] = points[i].v;
				max_pre[i+n] = max(0, points[i].v);
				max_suf[i+n] = max(0, points[i].v);
				max_cont[i+n] = max(0, points[i].v);
			}
			else {
				sum[i+n] = 0;
				max_pre[i+n] = 0;
				max_suf[i+n] = 0;
				max_cont[i+n] = 0;
			}
		}
		for (int i = n-1; i >= 0; i--) reset(i);
	}
	void reset(int i) {
		assert(i < n);
		sum[i] = sum[2*i]+sum[2*i+1];
		max_pre[i] = max(max_pre[2*i], sum[2*i]+max_pre[2*i+1]);
		max_suf[i] = max(max_suf[2*i+1], max_suf[2*i]+sum[2*i+1]);
		max_cont[i] = max(max(max_cont[2*i], max_cont[2*i+1]), max_suf[2*i]+max_pre[2*i+1]);
	}
	void update(int i) {
		sum[i+n] = points[i].v;
		max_pre[i+n] = max(0, points[i].v);
		max_suf[i+n] = max(0, points[i].v);
		max_cont[i+n] = max(0, points[i].v);
		i += n;
		while (i > 1) {
			i /= 2;
			reset(i);
		}
	}
	ll max_sum() {
		return max_cont[1];
	}
};

void make_upd(int i, int j) {
	if (points[i].x == points[j].x) return;
	ld ang = get_ang(i, j);
	updates[t++] = pdi(ang, i);
	updates[t++] = pdi(ang, j);
}

void swap(int a, int b, STree &s) {
	int i = curpos[a];
	int j = curpos[b];
	Point temp = points[i];
	points[i] = points[j];
	points[j] = temp;
	s.update(i);
	s.update(j);
	curpos[a] = j;
	curpos[b] = i;
}

void swap(vector<int> &v, STree &s) {
	for (int j = 0; j < v.size()/2; j++) {
		swap(v[j], v[v.size()-1-j], s);
	}
}

bool on_line(ld ang, int i, int j) {
	ld yval = ang*(points[j].x-points[i].x)+points[i].y;
	return (abs(yval-points[j].y) < ERROR);
}

struct comp {
	bool operator()(const int &a, const int &b) {
		return (curpos[a] < curpos[b]);
	}
};

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x, y, w;
		cin >> x >> y >> w;
		points[i] = Point(x, y, w);
	}
	sort(points, points+n);
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			make_upd(i, j);
		}
	}
	iota(curpos, curpos+n, 0);
	STree s(n);
	ll best = s.max_sum();
	sort(updates, updates+t);
	for (int i = 0; i < t;) {
		ld ang = updates[i].first;
		int orig = i;
		set<int, comp> cur_vals;
		while (i < t && abs(updates[i].first-ang) < ERROR) {
			cur_vals.insert(updates[i].second);
			i++;
		}
		vector<int> cur_line;
		for (int v: cur_vals) {
			if (cur_line.empty() || on_line(ang, curpos[cur_line.back()], curpos[v])) cur_line.push_back(v);
			else {
				swap(cur_line, s);
				cur_line.clear();
				cur_line.push_back(v);
			}
		}
		assert(cur_line.size());
		swap(cur_line, s);
		best = max(best, s.max_sum());
	}
	cout << best << "\n";
}

Compilation message

bulldozer.cpp: In function 'void swap(std::vector<int>&, STree&)':
bulldozer.cpp:110:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |  for (int j = 0; j < v.size()/2; j++) {
      |                  ~~^~~~~~~~~~~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:146:7: warning: unused variable 'orig' [-Wunused-variable]
  146 |   int orig = i;
      |       ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 556 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 5 ms 596 KB Output is correct
6 Correct 3 ms 580 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 4 ms 588 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 4 ms 596 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 5 ms 596 KB Output is correct
6 Correct 3 ms 580 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 4 ms 588 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 4 ms 596 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 5 ms 596 KB Output is correct
6 Correct 3 ms 580 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 4 ms 588 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 4 ms 596 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 556 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 4 ms 596 KB Output is correct
19 Correct 3 ms 608 KB Output is correct
20 Correct 5 ms 596 KB Output is correct
21 Correct 3 ms 580 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 4 ms 588 KB Output is correct
24 Correct 4 ms 596 KB Output is correct
25 Correct 3 ms 596 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Incorrect 4 ms 596 KB Output isn't correct
37 Halted 0 ms 0 KB -