Submission #26554

# Submission time Handle Problem Language Result Execution time Memory
26554 2017-07-03T02:01:57 Z model_code Bulldozer (JOI17_bulldozer) C++11
100 / 100
539 ms 50068 KB
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

typedef long long ll;

const int MAX_N = 4002;
const int seg_siz = 1<<13;
const ll INF = 10000000000000;

struct SEG{
	ll s[seg_siz],t[seg_siz],u[seg_siz];
	int siz = seg_siz>>1;
	void init(){
		for(int i = 0 ; i < siz*2-1 ; i ++){
			s[i] = -INF;
			t[i] = INF;
			u[i] = 0;
		}
	}
	void update(int k,ll x){
		k += siz-1;
		s[k] = x;
		t[k] = x;
		while(k > 0){
			k = (k-1)/2;
			s[k] = max(s[2*k+1],s[2*k+2]);
			t[k] = min(t[2*k+1],t[2*k+2]);
			u[k] = max(u[2*k+1],u[2*k+2]);
			u[k] = max(u[k],s[2*k+2]-t[2*k+1]);
		}
	}
}seg;

int main(){
	int n;
	ll x[MAX_N],y[MAX_N],w[MAX_N];
	scanf("%d",&n);
	for(int i = 0 ; i < n ; i ++){
		scanf("%lld%lld%lld",&x[i],&y[i],&w[i]);
	}
	
	vector<pair<pair<ll,ll>,ll>> Points;
	for(int i = 0 ; i < n ; i ++){
		Points.push_back(pair<pair<ll,ll>,ll>(pair<ll,ll>(x[i],y[i]),w[i]));
	}
	sort(Points.begin(),Points.end());
	for(int i = 0 ; i < n ; i ++){
		x[i] = Points[i].first.first;
		y[i] = Points[i].first.second;
		w[i] = Points[i].second;
	}
	
	vector<pair<pair<ll,ll>,pair<int,int>>> Swap;
	for(int i = 0 ; i < n ; i ++){
		for(int j = 0 ; j < n ; j ++){
			if(x[i] < x[j])Swap.push_back(pair<pair<ll,ll>,pair<int,int>>(pair<ll,ll>(y[i]-y[j],x[j]-x[i]),pair<int,int>(min(i,j),max(i,j))));
		}
	}
	sort(Swap.begin(),Swap.end(),
		[](pair<pair<ll,ll>,pair<int,int>> a,pair<pair<ll,ll>,pair<int,int>> b){
			if(a.first.first*b.first.second == a.first.second*b.first.first){
				return a.second > b.second;
			}
			else return a.first.first*b.first.second > a.first.second*b.first.first;
		}
	);
	
	ll s[MAX_N] = {};
	s[0] = 0;
	for(int i = 1 ; i <= n ; i ++){
		s[i] = s[i-1]+w[i-1];
	}
	int t[MAX_N] = {};
	for(int i = 0 ; i < n ; i ++){
		t[i] = i+1;
	}
	
	seg.init();
	for(int i = 0 ; i <= n ; i ++){
		seg.update(i,s[i]);
	}
	ll ret = seg.u[0];
	
	for(int i = 0 ; i < Swap.size() ; i ++){
		pair<int,int> p = Swap[i].second;
		s[t[p.first]] += s[t[p.first]+1] - 2*s[t[p.first]] + s[t[p.first]-1];
		seg.update(t[p.first],s[t[p.first]]);
		swap(t[p.first],t[p.second]);
		
		if(i == Swap.size()-1){
			ret = max( ret , seg.u[0] );
			break;
		}
		pair<ll,ll> q = Swap[i].first , r = Swap[i+1].first;
		if(q.first*r.second != q.second*r.first){
			ret = max( ret , seg.u[0] );
		}
	}
	
	cout << ret << endl;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:86:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0 ; i < Swap.size() ; i ++){
                  ~~^~~~~~~~~~~~~
bulldozer.cpp:92:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i == Swap.size()-1){
      ~~^~~~~~~~~~~~~~~~
bulldozer.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
bulldozer.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld",&x[i],&y[i],&w[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 836 KB Output is correct
2 Correct 3 ms 836 KB Output is correct
3 Correct 2 ms 864 KB Output is correct
4 Correct 3 ms 836 KB Output is correct
5 Correct 3 ms 836 KB Output is correct
6 Correct 3 ms 836 KB Output is correct
7 Correct 3 ms 836 KB Output is correct
8 Correct 3 ms 836 KB Output is correct
9 Correct 3 ms 884 KB Output is correct
10 Correct 3 ms 836 KB Output is correct
11 Correct 2 ms 616 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 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 836 KB Output is correct
2 Correct 3 ms 836 KB Output is correct
3 Correct 3 ms 836 KB Output is correct
4 Correct 3 ms 836 KB Output is correct
5 Correct 3 ms 788 KB Output is correct
6 Correct 3 ms 836 KB Output is correct
7 Correct 3 ms 776 KB Output is correct
8 Correct 3 ms 836 KB Output is correct
9 Correct 3 ms 836 KB Output is correct
10 Correct 3 ms 836 KB Output is correct
11 Correct 2 ms 512 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 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 3 ms 836 KB Output is correct
22 Correct 3 ms 836 KB Output is correct
23 Correct 3 ms 836 KB Output is correct
24 Correct 3 ms 836 KB Output is correct
25 Correct 3 ms 836 KB Output is correct
26 Correct 3 ms 836 KB Output is correct
27 Correct 3 ms 808 KB Output is correct
28 Correct 3 ms 836 KB Output is correct
29 Correct 3 ms 836 KB Output is correct
30 Correct 3 ms 836 KB Output is correct
31 Correct 3 ms 836 KB Output is correct
32 Correct 3 ms 836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 836 KB Output is correct
2 Correct 3 ms 836 KB Output is correct
3 Correct 3 ms 836 KB Output is correct
4 Correct 3 ms 836 KB Output is correct
5 Correct 3 ms 788 KB Output is correct
6 Correct 3 ms 836 KB Output is correct
7 Correct 3 ms 776 KB Output is correct
8 Correct 3 ms 836 KB Output is correct
9 Correct 3 ms 836 KB Output is correct
10 Correct 3 ms 836 KB Output is correct
11 Correct 2 ms 512 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 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 3 ms 836 KB Output is correct
22 Correct 3 ms 836 KB Output is correct
23 Correct 3 ms 836 KB Output is correct
24 Correct 3 ms 836 KB Output is correct
25 Correct 3 ms 836 KB Output is correct
26 Correct 3 ms 836 KB Output is correct
27 Correct 3 ms 808 KB Output is correct
28 Correct 3 ms 836 KB Output is correct
29 Correct 3 ms 836 KB Output is correct
30 Correct 3 ms 836 KB Output is correct
31 Correct 3 ms 836 KB Output is correct
32 Correct 3 ms 836 KB Output is correct
33 Correct 503 ms 49920 KB Output is correct
34 Correct 498 ms 49888 KB Output is correct
35 Correct 497 ms 49884 KB Output is correct
36 Correct 508 ms 49968 KB Output is correct
37 Correct 479 ms 49984 KB Output is correct
38 Correct 506 ms 49884 KB Output is correct
39 Correct 505 ms 49928 KB Output is correct
40 Correct 505 ms 49920 KB Output is correct
41 Correct 498 ms 49884 KB Output is correct
42 Correct 490 ms 49884 KB Output is correct
43 Correct 480 ms 49932 KB Output is correct
44 Correct 475 ms 50012 KB Output is correct
45 Correct 481 ms 49884 KB Output is correct
46 Correct 483 ms 50004 KB Output is correct
47 Correct 471 ms 49912 KB Output is correct
48 Correct 491 ms 49892 KB Output is correct
49 Correct 493 ms 49884 KB Output is correct
50 Correct 510 ms 49884 KB Output is correct
51 Correct 509 ms 49952 KB Output is correct
52 Correct 488 ms 49856 KB Output is correct
53 Correct 470 ms 49852 KB Output is correct
54 Correct 489 ms 49884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 836 KB Output is correct
2 Correct 3 ms 836 KB Output is correct
3 Correct 3 ms 836 KB Output is correct
4 Correct 3 ms 836 KB Output is correct
5 Correct 3 ms 788 KB Output is correct
6 Correct 3 ms 836 KB Output is correct
7 Correct 3 ms 776 KB Output is correct
8 Correct 3 ms 836 KB Output is correct
9 Correct 3 ms 836 KB Output is correct
10 Correct 3 ms 836 KB Output is correct
11 Correct 2 ms 512 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 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 3 ms 836 KB Output is correct
22 Correct 3 ms 836 KB Output is correct
23 Correct 3 ms 836 KB Output is correct
24 Correct 3 ms 836 KB Output is correct
25 Correct 3 ms 836 KB Output is correct
26 Correct 3 ms 836 KB Output is correct
27 Correct 3 ms 808 KB Output is correct
28 Correct 3 ms 836 KB Output is correct
29 Correct 3 ms 836 KB Output is correct
30 Correct 3 ms 836 KB Output is correct
31 Correct 3 ms 836 KB Output is correct
32 Correct 3 ms 836 KB Output is correct
33 Correct 503 ms 49920 KB Output is correct
34 Correct 498 ms 49888 KB Output is correct
35 Correct 497 ms 49884 KB Output is correct
36 Correct 508 ms 49968 KB Output is correct
37 Correct 479 ms 49984 KB Output is correct
38 Correct 506 ms 49884 KB Output is correct
39 Correct 505 ms 49928 KB Output is correct
40 Correct 505 ms 49920 KB Output is correct
41 Correct 498 ms 49884 KB Output is correct
42 Correct 490 ms 49884 KB Output is correct
43 Correct 480 ms 49932 KB Output is correct
44 Correct 475 ms 50012 KB Output is correct
45 Correct 481 ms 49884 KB Output is correct
46 Correct 483 ms 50004 KB Output is correct
47 Correct 471 ms 49912 KB Output is correct
48 Correct 491 ms 49892 KB Output is correct
49 Correct 493 ms 49884 KB Output is correct
50 Correct 510 ms 49884 KB Output is correct
51 Correct 509 ms 49952 KB Output is correct
52 Correct 488 ms 49856 KB Output is correct
53 Correct 470 ms 49852 KB Output is correct
54 Correct 489 ms 49884 KB Output is correct
55 Correct 517 ms 49944 KB Output is correct
56 Correct 504 ms 49884 KB Output is correct
57 Correct 519 ms 50012 KB Output is correct
58 Correct 495 ms 50012 KB Output is correct
59 Correct 498 ms 50012 KB Output is correct
60 Correct 513 ms 49928 KB Output is correct
61 Correct 483 ms 49884 KB Output is correct
62 Correct 539 ms 49908 KB Output is correct
63 Correct 528 ms 49884 KB Output is correct
64 Correct 476 ms 49928 KB Output is correct
65 Correct 483 ms 49928 KB Output is correct
66 Correct 493 ms 50068 KB Output is correct
67 Correct 495 ms 49860 KB Output is correct
68 Correct 529 ms 49852 KB Output is correct
69 Correct 470 ms 49888 KB Output is correct
70 Correct 483 ms 49972 KB Output is correct
71 Correct 475 ms 49876 KB Output is correct
72 Correct 482 ms 49884 KB Output is correct
73 Correct 487 ms 49884 KB Output is correct
74 Correct 533 ms 49900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 836 KB Output is correct
2 Correct 3 ms 836 KB Output is correct
3 Correct 2 ms 864 KB Output is correct
4 Correct 3 ms 836 KB Output is correct
5 Correct 3 ms 836 KB Output is correct
6 Correct 3 ms 836 KB Output is correct
7 Correct 3 ms 836 KB Output is correct
8 Correct 3 ms 836 KB Output is correct
9 Correct 3 ms 884 KB Output is correct
10 Correct 3 ms 836 KB Output is correct
11 Correct 2 ms 616 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 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 3 ms 836 KB Output is correct
17 Correct 3 ms 836 KB Output is correct
18 Correct 3 ms 836 KB Output is correct
19 Correct 3 ms 836 KB Output is correct
20 Correct 3 ms 788 KB Output is correct
21 Correct 3 ms 836 KB Output is correct
22 Correct 3 ms 776 KB Output is correct
23 Correct 3 ms 836 KB Output is correct
24 Correct 3 ms 836 KB Output is correct
25 Correct 3 ms 836 KB Output is correct
26 Correct 2 ms 512 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 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 3 ms 836 KB Output is correct
37 Correct 3 ms 836 KB Output is correct
38 Correct 3 ms 836 KB Output is correct
39 Correct 3 ms 836 KB Output is correct
40 Correct 3 ms 836 KB Output is correct
41 Correct 3 ms 836 KB Output is correct
42 Correct 3 ms 808 KB Output is correct
43 Correct 3 ms 836 KB Output is correct
44 Correct 3 ms 836 KB Output is correct
45 Correct 3 ms 836 KB Output is correct
46 Correct 3 ms 836 KB Output is correct
47 Correct 3 ms 836 KB Output is correct
48 Correct 503 ms 49920 KB Output is correct
49 Correct 498 ms 49888 KB Output is correct
50 Correct 497 ms 49884 KB Output is correct
51 Correct 508 ms 49968 KB Output is correct
52 Correct 479 ms 49984 KB Output is correct
53 Correct 506 ms 49884 KB Output is correct
54 Correct 505 ms 49928 KB Output is correct
55 Correct 505 ms 49920 KB Output is correct
56 Correct 498 ms 49884 KB Output is correct
57 Correct 490 ms 49884 KB Output is correct
58 Correct 480 ms 49932 KB Output is correct
59 Correct 475 ms 50012 KB Output is correct
60 Correct 481 ms 49884 KB Output is correct
61 Correct 483 ms 50004 KB Output is correct
62 Correct 471 ms 49912 KB Output is correct
63 Correct 491 ms 49892 KB Output is correct
64 Correct 493 ms 49884 KB Output is correct
65 Correct 510 ms 49884 KB Output is correct
66 Correct 509 ms 49952 KB Output is correct
67 Correct 488 ms 49856 KB Output is correct
68 Correct 470 ms 49852 KB Output is correct
69 Correct 489 ms 49884 KB Output is correct
70 Correct 517 ms 49944 KB Output is correct
71 Correct 504 ms 49884 KB Output is correct
72 Correct 519 ms 50012 KB Output is correct
73 Correct 495 ms 50012 KB Output is correct
74 Correct 498 ms 50012 KB Output is correct
75 Correct 513 ms 49928 KB Output is correct
76 Correct 483 ms 49884 KB Output is correct
77 Correct 539 ms 49908 KB Output is correct
78 Correct 528 ms 49884 KB Output is correct
79 Correct 476 ms 49928 KB Output is correct
80 Correct 483 ms 49928 KB Output is correct
81 Correct 493 ms 50068 KB Output is correct
82 Correct 495 ms 49860 KB Output is correct
83 Correct 529 ms 49852 KB Output is correct
84 Correct 470 ms 49888 KB Output is correct
85 Correct 483 ms 49972 KB Output is correct
86 Correct 475 ms 49876 KB Output is correct
87 Correct 482 ms 49884 KB Output is correct
88 Correct 487 ms 49884 KB Output is correct
89 Correct 533 ms 49900 KB Output is correct
90 Correct 509 ms 49900 KB Output is correct
91 Correct 494 ms 49908 KB Output is correct
92 Correct 491 ms 49884 KB Output is correct
93 Correct 493 ms 50040 KB Output is correct
94 Correct 480 ms 49888 KB Output is correct
95 Correct 474 ms 49880 KB Output is correct
96 Correct 485 ms 49868 KB Output is correct
97 Correct 479 ms 49848 KB Output is correct
98 Correct 470 ms 49884 KB Output is correct
99 Correct 477 ms 49884 KB Output is correct
100 Correct 206 ms 25220 KB Output is correct
101 Correct 213 ms 25240 KB Output is correct
102 Correct 206 ms 25232 KB Output is correct
103 Correct 207 ms 25208 KB Output is correct
104 Correct 213 ms 25208 KB Output is correct
105 Correct 302 ms 49888 KB Output is correct
106 Correct 303 ms 49884 KB Output is correct
107 Correct 299 ms 49884 KB Output is correct
108 Correct 312 ms 49832 KB Output is correct
109 Correct 299 ms 49876 KB Output is correct
110 Correct 487 ms 49884 KB Output is correct
111 Correct 473 ms 49932 KB Output is correct
112 Correct 475 ms 49876 KB Output is correct
113 Correct 483 ms 49892 KB Output is correct
114 Correct 494 ms 49916 KB Output is correct
115 Correct 525 ms 49884 KB Output is correct
116 Correct 497 ms 49884 KB Output is correct
117 Correct 493 ms 49864 KB Output is correct
118 Correct 519 ms 49884 KB Output is correct
119 Correct 488 ms 50012 KB Output is correct
120 Correct 2 ms 640 KB Output is correct
121 Correct 2 ms 512 KB Output is correct
122 Correct 490 ms 49888 KB Output is correct
123 Correct 485 ms 49856 KB Output is correct
124 Correct 526 ms 49884 KB Output is correct
125 Correct 481 ms 49884 KB Output is correct
126 Correct 473 ms 49908 KB Output is correct
127 Correct 492 ms 49888 KB Output is correct
128 Correct 480 ms 49908 KB Output is correct
129 Correct 494 ms 49884 KB Output is correct
130 Correct 505 ms 49884 KB Output is correct
131 Correct 509 ms 49884 KB Output is correct
132 Correct 487 ms 49884 KB Output is correct
133 Correct 477 ms 49896 KB Output is correct