답안 #99680

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
99680 2019-03-06T06:09:21 Z square1001 Bulldozer (JOI17_bulldozer) C++14
20 / 100
2000 ms 109944 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;
}
long long solve(int N, vector<int> X, vector<int> Y, vector<long long> V) {
	vector<point> P(N);
	for(int i = 0; i < N; ++i) P[i] = point(X[i], Y[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;
	});
	vector<long long> ruiseki(N + 1);
	for(int i = 0; i < N; ++i) ruiseki[i + 1] = ruiseki[i] + V[perm[i]];
	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]);
		ruiseki[pos + 1] = ruiseki[pos] + ruiseki[pos + 2] - ruiseki[pos + 1];
		long long delta = max(-min(ruiseki[pos + 1] - ruiseki[pos], ruiseki[pos + 2] - ruiseki[pos + 1]), 0LL);
		for(int j = pos + 2; j <= N; ++j) {
			ans = max(ans, ruiseki[j] - ruiseki[pos] + delta);
		}
	}
	return ans;
}
int main() {
	int N;
	cin >> N;
	vector<int> X(N), Y(N); vector<long long> V(N);
	for(int i = 0; i < N; ++i) {
		cin >> X[i] >> Y[i] >> V[i];
	}
	long long ans = solve(N, X, Y, V);
	cout << ans << endl;
	return 0;
}

Compilation message

bulldozer.cpp: In function 'long long int solve(int, std::vector<int>, std::vector<int>, std::vector<long long int>)':
bulldozer.cpp:36:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < vec.size(); ++i) vecperm[i] = i;
                 ~~^~~~~~~~~~~~
bulldozer.cpp:47:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < vec.size(); ++i) {
                 ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 832 KB Output is correct
2 Correct 5 ms 832 KB Output is correct
3 Correct 5 ms 832 KB Output is correct
4 Correct 5 ms 832 KB Output is correct
5 Correct 4 ms 832 KB Output is correct
6 Correct 5 ms 832 KB Output is correct
7 Correct 4 ms 832 KB Output is correct
8 Correct 5 ms 832 KB Output is correct
9 Correct 5 ms 832 KB Output is correct
10 Correct 4 ms 832 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 304 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 5 ms 832 KB Output is correct
22 Correct 4 ms 832 KB Output is correct
23 Correct 5 ms 832 KB Output is correct
24 Correct 4 ms 832 KB Output is correct
25 Correct 4 ms 832 KB Output is correct
26 Correct 5 ms 832 KB Output is correct
27 Correct 5 ms 832 KB Output is correct
28 Correct 5 ms 832 KB Output is correct
29 Correct 5 ms 832 KB Output is correct
30 Correct 4 ms 832 KB Output is correct
31 Correct 5 ms 832 KB Output is correct
32 Correct 5 ms 832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 832 KB Output is correct
2 Correct 5 ms 832 KB Output is correct
3 Correct 5 ms 832 KB Output is correct
4 Correct 5 ms 832 KB Output is correct
5 Correct 4 ms 832 KB Output is correct
6 Correct 5 ms 832 KB Output is correct
7 Correct 4 ms 832 KB Output is correct
8 Correct 5 ms 832 KB Output is correct
9 Correct 5 ms 832 KB Output is correct
10 Correct 4 ms 832 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 304 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 5 ms 832 KB Output is correct
22 Correct 4 ms 832 KB Output is correct
23 Correct 5 ms 832 KB Output is correct
24 Correct 4 ms 832 KB Output is correct
25 Correct 4 ms 832 KB Output is correct
26 Correct 5 ms 832 KB Output is correct
27 Correct 5 ms 832 KB Output is correct
28 Correct 5 ms 832 KB Output is correct
29 Correct 5 ms 832 KB Output is correct
30 Correct 4 ms 832 KB Output is correct
31 Correct 5 ms 832 KB Output is correct
32 Correct 5 ms 832 KB Output is correct
33 Execution timed out 2066 ms 109944 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 832 KB Output is correct
2 Correct 5 ms 832 KB Output is correct
3 Correct 5 ms 832 KB Output is correct
4 Correct 5 ms 832 KB Output is correct
5 Correct 4 ms 832 KB Output is correct
6 Correct 5 ms 832 KB Output is correct
7 Correct 4 ms 832 KB Output is correct
8 Correct 5 ms 832 KB Output is correct
9 Correct 5 ms 832 KB Output is correct
10 Correct 4 ms 832 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 304 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 5 ms 832 KB Output is correct
22 Correct 4 ms 832 KB Output is correct
23 Correct 5 ms 832 KB Output is correct
24 Correct 4 ms 832 KB Output is correct
25 Correct 4 ms 832 KB Output is correct
26 Correct 5 ms 832 KB Output is correct
27 Correct 5 ms 832 KB Output is correct
28 Correct 5 ms 832 KB Output is correct
29 Correct 5 ms 832 KB Output is correct
30 Correct 4 ms 832 KB Output is correct
31 Correct 5 ms 832 KB Output is correct
32 Correct 5 ms 832 KB Output is correct
33 Execution timed out 2066 ms 109944 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 832 KB Output isn't correct
2 Halted 0 ms 0 KB -