답안 #26578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26578 2017-07-03T08:18:35 Z Bruteforceman Bulldozer (JOI17_bulldozer) C++11
25 / 100
2000 ms 468 KB
#include <bits/stdc++.h>
using namespace std;

int X[2005];
int Y[2005];
int C[2005];
int n;

double project(int p, double m) {
	return (-Y[p] / m) + X[p]; 
}
long long solve(int p, int q) {
	if(X[p] == X[q]) return 0;
	if(Y[p] == Y[q]) return 0;
	if(X[p] > X[q]) swap(p, q);
	double m = ((double)(Y[q] - Y[p])) / (X[q] - X[p]);
	
	double pos = project(p, m);
	
	vector <pair <double, int> > U, V;
	for(int i = 1; i <= n; i++) {
		double pp = project(i, m);
		if(i == p || i == q) continue;
		if(pp < pos) {
			U.push_back(make_pair(pp, C[i]));
		} else {
			V.push_back(make_pair(pp, C[i]));
		}
	}
	sort(U.begin(), U.end());
	sort(V.begin(), V.end());
	reverse(U.begin(), U.end());
	
	long long s1 = max(C[p], max(C[q], C[p] + C[q]));
	long long s2 = s1;
	long long ans = s1;
	
	for(auto i : U) {
		// cout << i.first << " " << i.second << endl;
		s1 += i.second;
		ans = max(ans, s1);
	}
	for(auto i : V) {
		s2 += i.second;
		ans = max(ans, s2);

	}
	return ans;
}

long long hehe(int x, int y) {
	long long ans = 0;
	for(int i = 1; i <= n; i++) {
		if(x <= X[i] && X[i] <= y) {
			ans += C[i];
		}
	}
	return ans;
}


int main() {
	scanf("%d", &n);
	bool good = true;
	for(int i = 1; i <= n; i++) {
		scanf("%d %d %d", &X[i], &Y[i], &C[i]);
		good &= (Y[i] == 0);
	}
	
	if(good) {
		long long res = 0;
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				if(X[i] <= X[j]) {
					res = max(res, hehe(X[i], X[j]));
				}
			}
		}
		cout << res << endl;
		exit(0);
	}
	
	long long sum = 0;
	for(int i = 1; i <= n; i++) {
		sum += C[i];
	}
	long long ans = 0;
	for(int i = 1; i <= n; i++) {
		ans = max(ans, 1LL * C[i]);
	}
	ans = max(ans, sum);
	for(int i = 1; i <= n; i++) {
		for(int j = i + 1; j <= n; j++) {
			ans = max(ans, solve(i, j));
		}
	}
	cout << ans << endl;
	return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
bulldozer.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &X[i], &Y[i], &C[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 4 ms 256 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 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 384 KB Output is correct
2 Correct 27 ms 256 KB Output is correct
3 Correct 28 ms 256 KB Output is correct
4 Correct 28 ms 408 KB Output is correct
5 Correct 37 ms 256 KB Output is correct
6 Correct 28 ms 408 KB Output is correct
7 Correct 28 ms 256 KB Output is correct
8 Correct 29 ms 384 KB Output is correct
9 Correct 28 ms 376 KB Output is correct
10 Correct 29 ms 256 KB Output is correct
11 Correct 2 ms 356 KB Output is correct
12 Correct 3 ms 384 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 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 26 ms 256 KB Output is correct
22 Correct 27 ms 384 KB Output is correct
23 Correct 35 ms 256 KB Output is correct
24 Correct 27 ms 384 KB Output is correct
25 Correct 28 ms 368 KB Output is correct
26 Correct 27 ms 256 KB Output is correct
27 Correct 26 ms 428 KB Output is correct
28 Correct 27 ms 388 KB Output is correct
29 Correct 26 ms 388 KB Output is correct
30 Correct 27 ms 372 KB Output is correct
31 Correct 26 ms 380 KB Output is correct
32 Correct 27 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 384 KB Output is correct
2 Correct 27 ms 256 KB Output is correct
3 Correct 28 ms 256 KB Output is correct
4 Correct 28 ms 408 KB Output is correct
5 Correct 37 ms 256 KB Output is correct
6 Correct 28 ms 408 KB Output is correct
7 Correct 28 ms 256 KB Output is correct
8 Correct 29 ms 384 KB Output is correct
9 Correct 28 ms 376 KB Output is correct
10 Correct 29 ms 256 KB Output is correct
11 Correct 2 ms 356 KB Output is correct
12 Correct 3 ms 384 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 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 26 ms 256 KB Output is correct
22 Correct 27 ms 384 KB Output is correct
23 Correct 35 ms 256 KB Output is correct
24 Correct 27 ms 384 KB Output is correct
25 Correct 28 ms 368 KB Output is correct
26 Correct 27 ms 256 KB Output is correct
27 Correct 26 ms 428 KB Output is correct
28 Correct 27 ms 388 KB Output is correct
29 Correct 26 ms 388 KB Output is correct
30 Correct 27 ms 372 KB Output is correct
31 Correct 26 ms 380 KB Output is correct
32 Correct 27 ms 384 KB Output is correct
33 Execution timed out 2017 ms 468 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 384 KB Output is correct
2 Correct 27 ms 256 KB Output is correct
3 Correct 28 ms 256 KB Output is correct
4 Correct 28 ms 408 KB Output is correct
5 Correct 37 ms 256 KB Output is correct
6 Correct 28 ms 408 KB Output is correct
7 Correct 28 ms 256 KB Output is correct
8 Correct 29 ms 384 KB Output is correct
9 Correct 28 ms 376 KB Output is correct
10 Correct 29 ms 256 KB Output is correct
11 Correct 2 ms 356 KB Output is correct
12 Correct 3 ms 384 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 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 26 ms 256 KB Output is correct
22 Correct 27 ms 384 KB Output is correct
23 Correct 35 ms 256 KB Output is correct
24 Correct 27 ms 384 KB Output is correct
25 Correct 28 ms 368 KB Output is correct
26 Correct 27 ms 256 KB Output is correct
27 Correct 26 ms 428 KB Output is correct
28 Correct 27 ms 388 KB Output is correct
29 Correct 26 ms 388 KB Output is correct
30 Correct 27 ms 372 KB Output is correct
31 Correct 26 ms 380 KB Output is correct
32 Correct 27 ms 384 KB Output is correct
33 Execution timed out 2017 ms 468 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 4 ms 256 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 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 27 ms 384 KB Output is correct
17 Correct 27 ms 256 KB Output is correct
18 Correct 28 ms 256 KB Output is correct
19 Correct 28 ms 408 KB Output is correct
20 Correct 37 ms 256 KB Output is correct
21 Correct 28 ms 408 KB Output is correct
22 Correct 28 ms 256 KB Output is correct
23 Correct 29 ms 384 KB Output is correct
24 Correct 28 ms 376 KB Output is correct
25 Correct 29 ms 256 KB Output is correct
26 Correct 2 ms 356 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2 ms 256 KB Output is correct
35 Correct 2 ms 256 KB Output is correct
36 Correct 26 ms 256 KB Output is correct
37 Correct 27 ms 384 KB Output is correct
38 Correct 35 ms 256 KB Output is correct
39 Correct 27 ms 384 KB Output is correct
40 Correct 28 ms 368 KB Output is correct
41 Correct 27 ms 256 KB Output is correct
42 Correct 26 ms 428 KB Output is correct
43 Correct 27 ms 388 KB Output is correct
44 Correct 26 ms 388 KB Output is correct
45 Correct 27 ms 372 KB Output is correct
46 Correct 26 ms 380 KB Output is correct
47 Correct 27 ms 384 KB Output is correct
48 Execution timed out 2017 ms 468 KB Time limit exceeded
49 Halted 0 ms 0 KB -