Submission #99664

# Submission time Handle Problem Language Result Execution time Memory
99664 2019-03-06T04:53:25 Z square1001 Bulldozer (JOI17_bulldozer) C++14
0 / 100
5 ms 1148 KB
#include <tuple>
#include <vector>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
struct point {
	long long x, y;
	point() : x(0), y(0) {};
	point(long long x_, long long y_) : x(x_), y(y_) {};
	point operator+(const point& p) const { return point(x + p.x, y + p.y); }
	point operator-(const point& p) const { return point(x - p.x, y - p.y); }
	long long cross(const point& p) const { return x * p.y - y * p.x; }
};
int shougen(const point &p) {
	if(p.y == 0) return p.x > 0 ? 0 : 4;
	if(p.x == 0) return p.y > 0 ? 2 : 6;
	if(p.y > 0) return p.x > 0 ? 1 : 3;
	return p.x > 0 ? 7 : 5;
}
int main() {
	int N;
	cin >> N;
	vector<point> P(N);
	vector<long long> V(N);
	for(int i = 0; i < N; ++i) {
		cin >> P[i].x >> P[i].y >> V[i];
	}
	vector<int> perm(N);
	for(int i = 0; i < N; ++i) perm[i] = i;
	sort(perm.begin(), perm.end(), [&](int i, int j) { return P[i].y != P[j].y ? P[i].y < P[j].y : P[i].x < P[j].x; });
	vector<int> inv(N);
	for(int i = 0; i < N; ++i) inv[perm[i]] = i;
	vector<tuple<point, int, int> > vec;
	for(int i = 0; i < N; ++i) {
		for(int j = 0; j < N; ++j) {
			if(i != j) vec.push_back(make_tuple(P[i] - P[j], i, j));
		}
	}
	vector<int> vecperm(vec.size());
	for(int i = 0; i < vec.size(); ++i) vecperm[i] = i;
	sort(vecperm.begin(), vecperm.end(), [&](int i, int j) {
		point p1 = get<0>(vec[i]), p2 = get<0>(vec[j]);
		int s1 = shougen(p1), s2 = shougen(p2);
		if(s1 != s2) return s1 < s2;
		return p1.cross(p2) > 0;
	});
	for(int i = 1; i < vec.size(); ++i) {
		point p1 = get<0>(vec[vecperm[i - 1]]), p2 = get<0>(vec[vecperm[i]]);
		assert(p1.cross(p2) != 0);
	}
	long long ans = *max_element(V.begin(), V.end());
	ans = max(ans, 0LL);
	for(int i = 0; i < vec.size(); ++i) {
		int pa = get<1>(vec[vecperm[i]]), pb = get<2>(vec[vecperm[i]]);
		int pos = min(inv[pa], inv[pb]);
		swap(inv[pa], inv[pb]);
		swap(perm[pos], perm[pos + 1]);
		long long sum = V[perm[pos]];
		for(int j = pos + 1; j < N; ++j) {
			sum += V[perm[j]];
			ans = max(ans, sum);
		}
		//cout << get<0>(i).x << ' ' << get<0>(i).y << ' ' << pa << ' ' << pb << ' ' << pos << ' ' << sum << endl;
	}
	cout << ans << endl;
	return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:41:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < vec.size(); ++i) vecperm[i] = i;
                 ~~^~~~~~~~~~~~
bulldozer.cpp:48:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < vec.size(); ++i) {
                 ~~^~~~~~~~~~~~
bulldozer.cpp:54:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < vec.size(); ++i) {
                 ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1148 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1148 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -