Submission #514677

# Submission time Handle Problem Language Result Execution time Memory
514677 2022-01-18T10:48:30 Z amunduzbaev Bulldozer (JOI17_bulldozer) C++14
100 / 100
1082 ms 66252 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
#define int long long
 
const int N = 2005;
long double const eps = 1e-14;
 
struct ST{
	ar<int, 4> tree[N * 4];
	void merge(ar<int, 4>& x, ar<int, 4>& a, ar<int, 4>& b){
		x[0] = max({a[0], b[0], a[2] + b[1]});
		x[1] = max({a[1], a[3] + b[1]});
		x[2] = max({b[2], b[3] + a[2]});
		x[3] = a[3] + b[3];
	}
	
	void sett(int i, int v, int lx = 0, int rx = N, int x = 1){
		if(lx == rx){ 
			tree[x] = {max(v, 0ll), max(v, 0ll), max(v, 0ll), v}; return;
		} int m = (lx + rx) >> 1;
		if(i <= m) sett(i, v, lx, m, x<<1);
		else sett(i, v, m+1, rx, x<<1|1);
		merge(tree[x], tree[x<<1], tree[x<<1|1]);
	}
	
	int get(int i, int lx = 0, int rx = N, int x = 1){
		if(lx == rx) return tree[x][3];
		int m = (lx + rx) >> 1;
		if(i <= m) return get(i, lx, m, x<<1);
		else return get(i, m+1, rx, x<<1|1);
	}
}tree;
 
/*

5
1 1 3
2 2 -1
3 3 0
4 4 -1
5 5 3

6
0 1 10
0 5 10
3 0 10
3 3 -5
4 5 10
4 1 10

*/
 
signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
	
	int n; cin>>n;
	vector<ar<int, 3>> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	} sort(a.begin(), a.end(), [&](auto& a, auto& b){
		if(a[0] != b[0]) return a[0] < b[0];
		return a[1] > b[1];
	});
	//~ cout<<"\n";
	vector<pair<long double, pair<int, int>>> tt;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(a[i][0] == a[j][0]) continue;
			double slop = (a[j][1] - a[i][1]) * 1. / (a[i][0] - a[j][0]);
			//~ cout<<i<<" "<<j<<" "<<slop<<"\n";
			tt.push_back({slop, {i, j}});
		}
	}
	
	vector<int> pos(n);
	for(int i=0;i<n;i++) pos[i] = i, tree.sett(i, a[i][2]);
	int res = tree.tree[1][0];
	sort(tt.begin(), tt.end());
	
	vector<int> used(n);
	
	for(int l=0;l<(int)tt.size();){
		int k = l;
		vector<pair<int, int>> tmp;
		while(k < (int)tt.size() && tt[l].first == tt[k].first){ // - tt[k].first) < eps){
			tmp.push_back(tt[k].second); k++;
		} l = k;
		
		sort(tmp.begin(), tmp.end(), [&](auto& a, auto& b){
			return (abs(pos[a.first] - pos[a.second]) > abs(pos[b.first] - pos[b.second]));
		});
		
		for(auto [i, j] : tmp){
			if(used[i] || used[j]) continue;
			used[i] = used[j] = 1;
			swap(pos[i], pos[j]);
			tree.sett(pos[i], a[i][2]), 
			tree.sett(pos[j], a[j][2]);
		}
		
		for(auto [i, j] : tmp) used[i] = used[j] = 0;
		
		res = max(res, tree.tree[1][0]);
	}
	
	cout<<res<<"\n";
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:96:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   96 |   for(auto [i, j] : tmp){
      |            ^
bulldozer.cpp:104:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  104 |   for(auto [i, j] : tmp) used[i] = used[j] = 0;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 716 KB Output is correct
4 Correct 4 ms 716 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 4 ms 716 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 680 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 716 KB Output is correct
22 Correct 2 ms 716 KB Output is correct
23 Correct 3 ms 716 KB Output is correct
24 Correct 2 ms 716 KB Output is correct
25 Correct 3 ms 716 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 2 ms 716 KB Output is correct
29 Correct 2 ms 716 KB Output is correct
30 Correct 3 ms 644 KB Output is correct
31 Correct 2 ms 716 KB Output is correct
32 Correct 2 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 716 KB Output is correct
4 Correct 4 ms 716 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 4 ms 716 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 680 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 716 KB Output is correct
22 Correct 2 ms 716 KB Output is correct
23 Correct 3 ms 716 KB Output is correct
24 Correct 2 ms 716 KB Output is correct
25 Correct 3 ms 716 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 2 ms 716 KB Output is correct
29 Correct 2 ms 716 KB Output is correct
30 Correct 3 ms 644 KB Output is correct
31 Correct 2 ms 716 KB Output is correct
32 Correct 2 ms 716 KB Output is correct
33 Correct 968 ms 66116 KB Output is correct
34 Correct 956 ms 66168 KB Output is correct
35 Correct 1002 ms 66180 KB Output is correct
36 Correct 999 ms 66240 KB Output is correct
37 Correct 962 ms 66064 KB Output is correct
38 Correct 998 ms 66148 KB Output is correct
39 Correct 1022 ms 66180 KB Output is correct
40 Correct 963 ms 66076 KB Output is correct
41 Correct 1016 ms 66180 KB Output is correct
42 Correct 1014 ms 66160 KB Output is correct
43 Correct 960 ms 66192 KB Output is correct
44 Correct 946 ms 66168 KB Output is correct
45 Correct 961 ms 66144 KB Output is correct
46 Correct 985 ms 66164 KB Output is correct
47 Correct 953 ms 66088 KB Output is correct
48 Correct 984 ms 66180 KB Output is correct
49 Correct 960 ms 66148 KB Output is correct
50 Correct 956 ms 66176 KB Output is correct
51 Correct 968 ms 66116 KB Output is correct
52 Correct 943 ms 66180 KB Output is correct
53 Correct 962 ms 66144 KB Output is correct
54 Correct 968 ms 66144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 716 KB Output is correct
4 Correct 4 ms 716 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 4 ms 716 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 680 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 716 KB Output is correct
22 Correct 2 ms 716 KB Output is correct
23 Correct 3 ms 716 KB Output is correct
24 Correct 2 ms 716 KB Output is correct
25 Correct 3 ms 716 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 2 ms 716 KB Output is correct
29 Correct 2 ms 716 KB Output is correct
30 Correct 3 ms 644 KB Output is correct
31 Correct 2 ms 716 KB Output is correct
32 Correct 2 ms 716 KB Output is correct
33 Correct 968 ms 66116 KB Output is correct
34 Correct 956 ms 66168 KB Output is correct
35 Correct 1002 ms 66180 KB Output is correct
36 Correct 999 ms 66240 KB Output is correct
37 Correct 962 ms 66064 KB Output is correct
38 Correct 998 ms 66148 KB Output is correct
39 Correct 1022 ms 66180 KB Output is correct
40 Correct 963 ms 66076 KB Output is correct
41 Correct 1016 ms 66180 KB Output is correct
42 Correct 1014 ms 66160 KB Output is correct
43 Correct 960 ms 66192 KB Output is correct
44 Correct 946 ms 66168 KB Output is correct
45 Correct 961 ms 66144 KB Output is correct
46 Correct 985 ms 66164 KB Output is correct
47 Correct 953 ms 66088 KB Output is correct
48 Correct 984 ms 66180 KB Output is correct
49 Correct 960 ms 66148 KB Output is correct
50 Correct 956 ms 66176 KB Output is correct
51 Correct 968 ms 66116 KB Output is correct
52 Correct 943 ms 66180 KB Output is correct
53 Correct 962 ms 66144 KB Output is correct
54 Correct 968 ms 66144 KB Output is correct
55 Correct 973 ms 66120 KB Output is correct
56 Correct 971 ms 66148 KB Output is correct
57 Correct 956 ms 66064 KB Output is correct
58 Correct 965 ms 66164 KB Output is correct
59 Correct 989 ms 66084 KB Output is correct
60 Correct 960 ms 66092 KB Output is correct
61 Correct 951 ms 66052 KB Output is correct
62 Correct 982 ms 66184 KB Output is correct
63 Correct 976 ms 66140 KB Output is correct
64 Correct 964 ms 66140 KB Output is correct
65 Correct 969 ms 66108 KB Output is correct
66 Correct 977 ms 66252 KB Output is correct
67 Correct 965 ms 66164 KB Output is correct
68 Correct 994 ms 66088 KB Output is correct
69 Correct 964 ms 66152 KB Output is correct
70 Correct 982 ms 66096 KB Output is correct
71 Correct 951 ms 66108 KB Output is correct
72 Correct 1000 ms 66128 KB Output is correct
73 Correct 960 ms 66192 KB Output is correct
74 Correct 1002 ms 66188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 3 ms 716 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 4 ms 716 KB Output is correct
20 Correct 3 ms 716 KB Output is correct
21 Correct 4 ms 716 KB Output is correct
22 Correct 2 ms 716 KB Output is correct
23 Correct 2 ms 716 KB Output is correct
24 Correct 2 ms 680 KB Output is correct
25 Correct 2 ms 716 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 2 ms 716 KB Output is correct
37 Correct 2 ms 716 KB Output is correct
38 Correct 3 ms 716 KB Output is correct
39 Correct 2 ms 716 KB Output is correct
40 Correct 3 ms 716 KB Output is correct
41 Correct 3 ms 716 KB Output is correct
42 Correct 3 ms 716 KB Output is correct
43 Correct 2 ms 716 KB Output is correct
44 Correct 2 ms 716 KB Output is correct
45 Correct 3 ms 644 KB Output is correct
46 Correct 2 ms 716 KB Output is correct
47 Correct 2 ms 716 KB Output is correct
48 Correct 968 ms 66116 KB Output is correct
49 Correct 956 ms 66168 KB Output is correct
50 Correct 1002 ms 66180 KB Output is correct
51 Correct 999 ms 66240 KB Output is correct
52 Correct 962 ms 66064 KB Output is correct
53 Correct 998 ms 66148 KB Output is correct
54 Correct 1022 ms 66180 KB Output is correct
55 Correct 963 ms 66076 KB Output is correct
56 Correct 1016 ms 66180 KB Output is correct
57 Correct 1014 ms 66160 KB Output is correct
58 Correct 960 ms 66192 KB Output is correct
59 Correct 946 ms 66168 KB Output is correct
60 Correct 961 ms 66144 KB Output is correct
61 Correct 985 ms 66164 KB Output is correct
62 Correct 953 ms 66088 KB Output is correct
63 Correct 984 ms 66180 KB Output is correct
64 Correct 960 ms 66148 KB Output is correct
65 Correct 956 ms 66176 KB Output is correct
66 Correct 968 ms 66116 KB Output is correct
67 Correct 943 ms 66180 KB Output is correct
68 Correct 962 ms 66144 KB Output is correct
69 Correct 968 ms 66144 KB Output is correct
70 Correct 973 ms 66120 KB Output is correct
71 Correct 971 ms 66148 KB Output is correct
72 Correct 956 ms 66064 KB Output is correct
73 Correct 965 ms 66164 KB Output is correct
74 Correct 989 ms 66084 KB Output is correct
75 Correct 960 ms 66092 KB Output is correct
76 Correct 951 ms 66052 KB Output is correct
77 Correct 982 ms 66184 KB Output is correct
78 Correct 976 ms 66140 KB Output is correct
79 Correct 964 ms 66140 KB Output is correct
80 Correct 969 ms 66108 KB Output is correct
81 Correct 977 ms 66252 KB Output is correct
82 Correct 965 ms 66164 KB Output is correct
83 Correct 994 ms 66088 KB Output is correct
84 Correct 964 ms 66152 KB Output is correct
85 Correct 982 ms 66096 KB Output is correct
86 Correct 951 ms 66108 KB Output is correct
87 Correct 1000 ms 66128 KB Output is correct
88 Correct 960 ms 66192 KB Output is correct
89 Correct 1002 ms 66188 KB Output is correct
90 Correct 962 ms 66192 KB Output is correct
91 Correct 1016 ms 66040 KB Output is correct
92 Correct 1029 ms 66136 KB Output is correct
93 Correct 1018 ms 66132 KB Output is correct
94 Correct 981 ms 66088 KB Output is correct
95 Correct 985 ms 66092 KB Output is correct
96 Correct 951 ms 66128 KB Output is correct
97 Correct 952 ms 66140 KB Output is correct
98 Correct 980 ms 66176 KB Output is correct
99 Correct 967 ms 66160 KB Output is correct
100 Correct 442 ms 33344 KB Output is correct
101 Correct 433 ms 33324 KB Output is correct
102 Correct 447 ms 33328 KB Output is correct
103 Correct 437 ms 33340 KB Output is correct
104 Correct 463 ms 33456 KB Output is correct
105 Correct 599 ms 66196 KB Output is correct
106 Correct 611 ms 66064 KB Output is correct
107 Correct 616 ms 66152 KB Output is correct
108 Correct 607 ms 66128 KB Output is correct
109 Correct 596 ms 66116 KB Output is correct
110 Correct 784 ms 66216 KB Output is correct
111 Correct 786 ms 66168 KB Output is correct
112 Correct 765 ms 66180 KB Output is correct
113 Correct 777 ms 66148 KB Output is correct
114 Correct 800 ms 66196 KB Output is correct
115 Correct 817 ms 66048 KB Output is correct
116 Correct 851 ms 66044 KB Output is correct
117 Correct 785 ms 66140 KB Output is correct
118 Correct 798 ms 66096 KB Output is correct
119 Correct 835 ms 66176 KB Output is correct
120 Correct 0 ms 332 KB Output is correct
121 Correct 0 ms 320 KB Output is correct
122 Correct 967 ms 66240 KB Output is correct
123 Correct 994 ms 66192 KB Output is correct
124 Correct 1000 ms 66148 KB Output is correct
125 Correct 1033 ms 66148 KB Output is correct
126 Correct 990 ms 66148 KB Output is correct
127 Correct 1014 ms 66144 KB Output is correct
128 Correct 964 ms 66236 KB Output is correct
129 Correct 987 ms 66148 KB Output is correct
130 Correct 1010 ms 66180 KB Output is correct
131 Correct 977 ms 66148 KB Output is correct
132 Correct 1052 ms 66180 KB Output is correct
133 Correct 1082 ms 66228 KB Output is correct