답안 #514540

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
514540 2022-01-18T08:53:43 Z amunduzbaev Bulldozer (JOI17_bulldozer) C++14
25 / 100
2000 ms 66192 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array

const int N = 2005;
long double const eps = 1e-16;

struct ST{
	ar<long long, 4> tree[N * 4];
	void merge(ar<long long, 4>& x, ar<long long, 4>& a, ar<long long, 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, 0), max(v, 0), max(v, 0), 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]);
	}
}tree;

/*

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

6
2 2 10
4 1 10
5 2 10
2 5 10
4 4 -5
5 5 10

*/

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	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];
	});
	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;
			long double slop = (a[j][1] - a[i][1]) * 1. / (a[i][0] - a[j][0]);
			tt.push_back({slop, {i, j}});
		}
	} vector<int> pos(n), used(n);
	for(int i=0;i<n;i++) pos[i] = i, tree.sett(i, a[i][2]);
	long long res = tree.tree[1][0];
	sort(tt.begin(), tt.end(), [&](auto& a, auto& b){
		if(a.first != b.first) return a.first < b.first;
		return a.second.second - a.second.first > b.second.second - b.second.first;
	}); for(int l=0;l<(int)tt.size();){
		int k = l;
		while(k < (int)tt.size() && abs(tt[l].first - tt[k].first) < eps){
			auto [i, j] = tt[k].second; k++;
			if(used[j] || used[i]) 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]);
		} while(l < k) used[tt[l].second.first] = used[tt[l].second.second] = 0, l++;
		res = max(res, tree.tree[1][0]);
	}
	
	for(auto& x : a) swap(x[0], x[1]);
	sort(a.begin(), a.end(), [&](auto& a, auto& b){
		if(a[0] != b[0]) return a[0] < b[0];
		return a[1] > b[1];
	}); tt.clear();
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(a[i][0] == a[j][0]) continue;
			long double slop = (a[j][1] - a[i][1]) * 1. / (a[i][0] - a[j][0]);
			tt.push_back({slop, {i, j}});
		}
	} fill(used.begin(), used.end(), 0);
	for(int i=0;i<n;i++) pos[i] = i, tree.sett(i, a[i][2]);
	res = max(res, tree.tree[1][0]);
	sort(tt.begin(), tt.end(), [&](auto& a, auto& b){
		if(a.first != b.first) return a.first < b.first;
		return a.second.second - a.second.first > b.second.second - b.second.first;
	}); for(int l=0;l<(int)tt.size();){
		int k = l;
		while(k < (int)tt.size() && abs(tt[l].first - tt[k].first) < eps){
			auto [i, j] = tt[k].second; k++;
			if(used[j] || used[i]) 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]);
		} while(l < k) used[tt[l].second.first] = used[tt[l].second.second] = 0, l++;
		res = max(res, tree.tree[1][0]);
	}
	
	cout<<res<<"\n";
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:76:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   76 |    auto [i, j] = tt[k].second; k++;
      |         ^
bulldozer.cpp:105:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  105 |    auto [i, j] = tt[k].second; k++;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 592 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 4 ms 716 KB Output is correct
4 Correct 4 ms 716 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 4 ms 716 KB Output is correct
7 Correct 5 ms 716 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 4 ms 592 KB Output is correct
10 Correct 4 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 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 5 ms 640 KB Output is correct
22 Correct 4 ms 716 KB Output is correct
23 Correct 4 ms 592 KB Output is correct
24 Correct 4 ms 716 KB Output is correct
25 Correct 4 ms 592 KB Output is correct
26 Correct 4 ms 716 KB Output is correct
27 Correct 4 ms 716 KB Output is correct
28 Correct 4 ms 716 KB Output is correct
29 Correct 4 ms 592 KB Output is correct
30 Correct 4 ms 716 KB Output is correct
31 Correct 4 ms 592 KB Output is correct
32 Correct 4 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 592 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 4 ms 716 KB Output is correct
4 Correct 4 ms 716 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 4 ms 716 KB Output is correct
7 Correct 5 ms 716 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 4 ms 592 KB Output is correct
10 Correct 4 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 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 5 ms 640 KB Output is correct
22 Correct 4 ms 716 KB Output is correct
23 Correct 4 ms 592 KB Output is correct
24 Correct 4 ms 716 KB Output is correct
25 Correct 4 ms 592 KB Output is correct
26 Correct 4 ms 716 KB Output is correct
27 Correct 4 ms 716 KB Output is correct
28 Correct 4 ms 716 KB Output is correct
29 Correct 4 ms 592 KB Output is correct
30 Correct 4 ms 716 KB Output is correct
31 Correct 4 ms 592 KB Output is correct
32 Correct 4 ms 716 KB Output is correct
33 Correct 1910 ms 66032 KB Output is correct
34 Correct 1938 ms 66192 KB Output is correct
35 Execution timed out 2005 ms 66152 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 592 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 4 ms 716 KB Output is correct
4 Correct 4 ms 716 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 4 ms 716 KB Output is correct
7 Correct 5 ms 716 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 4 ms 592 KB Output is correct
10 Correct 4 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 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 5 ms 640 KB Output is correct
22 Correct 4 ms 716 KB Output is correct
23 Correct 4 ms 592 KB Output is correct
24 Correct 4 ms 716 KB Output is correct
25 Correct 4 ms 592 KB Output is correct
26 Correct 4 ms 716 KB Output is correct
27 Correct 4 ms 716 KB Output is correct
28 Correct 4 ms 716 KB Output is correct
29 Correct 4 ms 592 KB Output is correct
30 Correct 4 ms 716 KB Output is correct
31 Correct 4 ms 592 KB Output is correct
32 Correct 4 ms 716 KB Output is correct
33 Correct 1910 ms 66032 KB Output is correct
34 Correct 1938 ms 66192 KB Output is correct
35 Execution timed out 2005 ms 66152 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 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 4 ms 592 KB Output is correct
17 Correct 4 ms 716 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
19 Correct 4 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 4 ms 716 KB Output is correct
22 Correct 5 ms 716 KB Output is correct
23 Correct 5 ms 716 KB Output is correct
24 Correct 4 ms 592 KB Output is correct
25 Correct 4 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 0 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 5 ms 640 KB Output is correct
37 Correct 4 ms 716 KB Output is correct
38 Correct 4 ms 592 KB Output is correct
39 Correct 4 ms 716 KB Output is correct
40 Correct 4 ms 592 KB Output is correct
41 Correct 4 ms 716 KB Output is correct
42 Correct 4 ms 716 KB Output is correct
43 Correct 4 ms 716 KB Output is correct
44 Correct 4 ms 592 KB Output is correct
45 Correct 4 ms 716 KB Output is correct
46 Correct 4 ms 592 KB Output is correct
47 Correct 4 ms 716 KB Output is correct
48 Correct 1910 ms 66032 KB Output is correct
49 Correct 1938 ms 66192 KB Output is correct
50 Execution timed out 2005 ms 66152 KB Time limit exceeded
51 Halted 0 ms 0 KB -