답안 #583692

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583692 2022-06-26T05:22:17 Z HIR180 Bulldozer (JOI17_bulldozer) C++17
100 / 100
1158 ms 102064 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i=0;i<n;i++)
typedef pair<int,int> P;
typedef pair<int, P> P1;
#define a first
#define b second
#define mp make_pair
#define eb emplace_back
template<class t>using vc = vector<t>;
using S = array<int, 4>;

S op(S a, S b){
	S c{};
	c[3] = a[3] + b[3];
	c[2] = max(b[2], a[2]+b[3]);
	c[1] = max(a[1], a[3]+b[1]);
	c[0] = max(max(a[0], b[0]), a[2]+b[1]);
	return c;
}
S e(){
	return S{(int)-1e18, (int)-1e18, (int)-1e18, 0};
}
S seg[1<<12];
void update(int pos, S a){
	pos += (1<<11)-1;
	seg[pos] = a;
	while(pos){
		pos = (pos-1) / 2;
		seg[pos] = op(seg[pos*2+1], seg[pos*2+2]);
	}
}
int n, x[2005], y[2005], c[2005];
P dir[2005][2005];

signed main(){
	cin >> n;
	vc<P1>vec(n);
	rep(i, n) cin >> vec[i].b.a >> vec[i].b.b >> vec[i].a;
	
	sort(vec.begin(), vec.end(), [](P1 a, P1 b){
		return mp(a.b.b, a.b.a) < mp(b.b.b, b.b.a);
	});
	
	using d = long double;
	vc<pair<d,P>>ev;
	
	rep(i, n) for(int j=i+1;j<n;j++){
		auto p1 = vec[i].b;
		auto p2 = vec[j].b;
		if(p1 > p2) swap(p1, p2);
		int dx = p2.a - p1.a;
		int dy = p2.b - p1.b;
		
		if(p1.b <= p2.b){
			ev.eb(atan2((d)dy, (d)dx), mp(i, j));
			dir[i][j] = mp(dx, dy);
		}
		else{
			ev.eb(atan2((d)dy*-1, (d)dx*-1), mp(i, j));
			dir[i][j] = mp(-dx, -dy);
		}
	}
	
	sort(ev.begin(), ev.end());
	rep(i, (1<<12)) seg[i] = e();
	rep(i, n){
		int a = vec[i].a;
		update(i,S{max(0LL,a), max(0LL,a), max(0LL,a), a});
	}
	vc<int>rev(n);
	rep(i, n) rev[i] = i;
	
	int ans = seg[0][0];
	rep(_, ev.size()){
		d deg = ev[_].a;
		int u = ev[_].b.a;
		int v = ev[_].b.b;
		//swap
		update(rev[u], S{max(0LL, vec[v].a), max(0LL, vec[v].a), max(0LL, vec[v].a), vec[v].a});
		update(rev[v], S{max(0LL, vec[u].a), max(0LL, vec[u].a), max(0LL, vec[u].a), vec[u].a});
		
		swap(rev[u], rev[v]);
		
		bool ok = (_+1 == ev.size());
		if(!ok){
			P p = dir[ev[_].b.a][ev[_].b.b];
			P q = dir[ev[_+1].b.a][ev[_+1].b.b];
			
			if(p.b * q.a != p.a * q.b) ok = true;
			if(p.a * q.a + p.b * q.b < 0) ok = true;
		}
		if(ok){
			ans = max(ans, seg[0][0]);
		}
	}
	cout << ans << '\n';
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:4:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long double, std::pair<long long int, long long int> >, std::allocator<std::pair<long double, std::pair<long long int, long long int> > > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(i, n) for(int i=0;i<n;i++)
......
   76 |  rep(_, ev.size()){
      |      ~~~~~~~~~~~~               
bulldozer.cpp:76:2: note: in expansion of macro 'rep'
   76 |  rep(_, ev.size()){
      |  ^~~
bulldozer.cpp:86:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long double, std::pair<long long int, long long int> >, std::allocator<std::pair<long double, std::pair<long long int, long long int> > > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |   bool ok = (_+1 == ev.size());
      |              ~~~~^~~~~~~~~~~~
bulldozer.cpp:77:5: warning: unused variable 'deg' [-Wunused-variable]
   77 |   d deg = ev[_].a;
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1104 KB Output is correct
2 Correct 2 ms 1104 KB Output is correct
3 Correct 2 ms 1104 KB Output is correct
4 Correct 2 ms 1104 KB Output is correct
5 Correct 2 ms 1104 KB Output is correct
6 Correct 2 ms 1104 KB Output is correct
7 Correct 2 ms 1104 KB Output is correct
8 Correct 2 ms 1104 KB Output is correct
9 Correct 2 ms 1104 KB Output is correct
10 Correct 2 ms 1104 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1104 KB Output is correct
2 Correct 2 ms 1104 KB Output is correct
3 Correct 3 ms 1104 KB Output is correct
4 Correct 2 ms 1104 KB Output is correct
5 Correct 3 ms 1104 KB Output is correct
6 Correct 3 ms 1104 KB Output is correct
7 Correct 3 ms 1104 KB Output is correct
8 Correct 2 ms 1104 KB Output is correct
9 Correct 4 ms 1104 KB Output is correct
10 Correct 3 ms 1104 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 3 ms 1104 KB Output is correct
22 Correct 3 ms 1104 KB Output is correct
23 Correct 4 ms 1104 KB Output is correct
24 Correct 3 ms 1104 KB Output is correct
25 Correct 3 ms 1104 KB Output is correct
26 Correct 3 ms 1104 KB Output is correct
27 Correct 3 ms 1104 KB Output is correct
28 Correct 3 ms 1104 KB Output is correct
29 Correct 2 ms 1104 KB Output is correct
30 Correct 3 ms 1084 KB Output is correct
31 Correct 3 ms 1104 KB Output is correct
32 Correct 3 ms 1104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1104 KB Output is correct
2 Correct 2 ms 1104 KB Output is correct
3 Correct 3 ms 1104 KB Output is correct
4 Correct 2 ms 1104 KB Output is correct
5 Correct 3 ms 1104 KB Output is correct
6 Correct 3 ms 1104 KB Output is correct
7 Correct 3 ms 1104 KB Output is correct
8 Correct 2 ms 1104 KB Output is correct
9 Correct 4 ms 1104 KB Output is correct
10 Correct 3 ms 1104 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 3 ms 1104 KB Output is correct
22 Correct 3 ms 1104 KB Output is correct
23 Correct 4 ms 1104 KB Output is correct
24 Correct 3 ms 1104 KB Output is correct
25 Correct 3 ms 1104 KB Output is correct
26 Correct 3 ms 1104 KB Output is correct
27 Correct 3 ms 1104 KB Output is correct
28 Correct 3 ms 1104 KB Output is correct
29 Correct 2 ms 1104 KB Output is correct
30 Correct 3 ms 1084 KB Output is correct
31 Correct 3 ms 1104 KB Output is correct
32 Correct 3 ms 1104 KB Output is correct
33 Correct 1071 ms 101904 KB Output is correct
34 Correct 1068 ms 101912 KB Output is correct
35 Correct 1158 ms 101908 KB Output is correct
36 Correct 1030 ms 101932 KB Output is correct
37 Correct 1083 ms 102036 KB Output is correct
38 Correct 1104 ms 101916 KB Output is correct
39 Correct 1044 ms 102020 KB Output is correct
40 Correct 1054 ms 101924 KB Output is correct
41 Correct 1045 ms 102008 KB Output is correct
42 Correct 1054 ms 101908 KB Output is correct
43 Correct 1040 ms 101908 KB Output is correct
44 Correct 998 ms 101920 KB Output is correct
45 Correct 1031 ms 101916 KB Output is correct
46 Correct 1048 ms 101912 KB Output is correct
47 Correct 1008 ms 101908 KB Output is correct
48 Correct 1016 ms 101960 KB Output is correct
49 Correct 1012 ms 101932 KB Output is correct
50 Correct 1107 ms 101924 KB Output is correct
51 Correct 1063 ms 101916 KB Output is correct
52 Correct 1042 ms 101916 KB Output is correct
53 Correct 1025 ms 101912 KB Output is correct
54 Correct 1014 ms 102004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1104 KB Output is correct
2 Correct 2 ms 1104 KB Output is correct
3 Correct 3 ms 1104 KB Output is correct
4 Correct 2 ms 1104 KB Output is correct
5 Correct 3 ms 1104 KB Output is correct
6 Correct 3 ms 1104 KB Output is correct
7 Correct 3 ms 1104 KB Output is correct
8 Correct 2 ms 1104 KB Output is correct
9 Correct 4 ms 1104 KB Output is correct
10 Correct 3 ms 1104 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 3 ms 1104 KB Output is correct
22 Correct 3 ms 1104 KB Output is correct
23 Correct 4 ms 1104 KB Output is correct
24 Correct 3 ms 1104 KB Output is correct
25 Correct 3 ms 1104 KB Output is correct
26 Correct 3 ms 1104 KB Output is correct
27 Correct 3 ms 1104 KB Output is correct
28 Correct 3 ms 1104 KB Output is correct
29 Correct 2 ms 1104 KB Output is correct
30 Correct 3 ms 1084 KB Output is correct
31 Correct 3 ms 1104 KB Output is correct
32 Correct 3 ms 1104 KB Output is correct
33 Correct 1071 ms 101904 KB Output is correct
34 Correct 1068 ms 101912 KB Output is correct
35 Correct 1158 ms 101908 KB Output is correct
36 Correct 1030 ms 101932 KB Output is correct
37 Correct 1083 ms 102036 KB Output is correct
38 Correct 1104 ms 101916 KB Output is correct
39 Correct 1044 ms 102020 KB Output is correct
40 Correct 1054 ms 101924 KB Output is correct
41 Correct 1045 ms 102008 KB Output is correct
42 Correct 1054 ms 101908 KB Output is correct
43 Correct 1040 ms 101908 KB Output is correct
44 Correct 998 ms 101920 KB Output is correct
45 Correct 1031 ms 101916 KB Output is correct
46 Correct 1048 ms 101912 KB Output is correct
47 Correct 1008 ms 101908 KB Output is correct
48 Correct 1016 ms 101960 KB Output is correct
49 Correct 1012 ms 101932 KB Output is correct
50 Correct 1107 ms 101924 KB Output is correct
51 Correct 1063 ms 101916 KB Output is correct
52 Correct 1042 ms 101916 KB Output is correct
53 Correct 1025 ms 101912 KB Output is correct
54 Correct 1014 ms 102004 KB Output is correct
55 Correct 1060 ms 102044 KB Output is correct
56 Correct 1016 ms 101956 KB Output is correct
57 Correct 1045 ms 101912 KB Output is correct
58 Correct 1058 ms 101932 KB Output is correct
59 Correct 1061 ms 102024 KB Output is correct
60 Correct 1063 ms 101936 KB Output is correct
61 Correct 1053 ms 101920 KB Output is correct
62 Correct 1085 ms 101936 KB Output is correct
63 Correct 1042 ms 101916 KB Output is correct
64 Correct 1028 ms 101928 KB Output is correct
65 Correct 1049 ms 101964 KB Output is correct
66 Correct 1042 ms 101960 KB Output is correct
67 Correct 1043 ms 101996 KB Output is correct
68 Correct 1112 ms 101912 KB Output is correct
69 Correct 1035 ms 101908 KB Output is correct
70 Correct 1078 ms 101916 KB Output is correct
71 Correct 1089 ms 101928 KB Output is correct
72 Correct 1035 ms 101952 KB Output is correct
73 Correct 1014 ms 102000 KB Output is correct
74 Correct 1039 ms 101952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1104 KB Output is correct
2 Correct 2 ms 1104 KB Output is correct
3 Correct 2 ms 1104 KB Output is correct
4 Correct 2 ms 1104 KB Output is correct
5 Correct 2 ms 1104 KB Output is correct
6 Correct 2 ms 1104 KB Output is correct
7 Correct 2 ms 1104 KB Output is correct
8 Correct 2 ms 1104 KB Output is correct
9 Correct 2 ms 1104 KB Output is correct
10 Correct 2 ms 1104 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 3 ms 1104 KB Output is correct
17 Correct 2 ms 1104 KB Output is correct
18 Correct 3 ms 1104 KB Output is correct
19 Correct 2 ms 1104 KB Output is correct
20 Correct 3 ms 1104 KB Output is correct
21 Correct 3 ms 1104 KB Output is correct
22 Correct 3 ms 1104 KB Output is correct
23 Correct 2 ms 1104 KB Output is correct
24 Correct 4 ms 1104 KB Output is correct
25 Correct 3 ms 1104 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 3 ms 1104 KB Output is correct
37 Correct 3 ms 1104 KB Output is correct
38 Correct 4 ms 1104 KB Output is correct
39 Correct 3 ms 1104 KB Output is correct
40 Correct 3 ms 1104 KB Output is correct
41 Correct 3 ms 1104 KB Output is correct
42 Correct 3 ms 1104 KB Output is correct
43 Correct 3 ms 1104 KB Output is correct
44 Correct 2 ms 1104 KB Output is correct
45 Correct 3 ms 1084 KB Output is correct
46 Correct 3 ms 1104 KB Output is correct
47 Correct 3 ms 1104 KB Output is correct
48 Correct 1071 ms 101904 KB Output is correct
49 Correct 1068 ms 101912 KB Output is correct
50 Correct 1158 ms 101908 KB Output is correct
51 Correct 1030 ms 101932 KB Output is correct
52 Correct 1083 ms 102036 KB Output is correct
53 Correct 1104 ms 101916 KB Output is correct
54 Correct 1044 ms 102020 KB Output is correct
55 Correct 1054 ms 101924 KB Output is correct
56 Correct 1045 ms 102008 KB Output is correct
57 Correct 1054 ms 101908 KB Output is correct
58 Correct 1040 ms 101908 KB Output is correct
59 Correct 998 ms 101920 KB Output is correct
60 Correct 1031 ms 101916 KB Output is correct
61 Correct 1048 ms 101912 KB Output is correct
62 Correct 1008 ms 101908 KB Output is correct
63 Correct 1016 ms 101960 KB Output is correct
64 Correct 1012 ms 101932 KB Output is correct
65 Correct 1107 ms 101924 KB Output is correct
66 Correct 1063 ms 101916 KB Output is correct
67 Correct 1042 ms 101916 KB Output is correct
68 Correct 1025 ms 101912 KB Output is correct
69 Correct 1014 ms 102004 KB Output is correct
70 Correct 1060 ms 102044 KB Output is correct
71 Correct 1016 ms 101956 KB Output is correct
72 Correct 1045 ms 101912 KB Output is correct
73 Correct 1058 ms 101932 KB Output is correct
74 Correct 1061 ms 102024 KB Output is correct
75 Correct 1063 ms 101936 KB Output is correct
76 Correct 1053 ms 101920 KB Output is correct
77 Correct 1085 ms 101936 KB Output is correct
78 Correct 1042 ms 101916 KB Output is correct
79 Correct 1028 ms 101928 KB Output is correct
80 Correct 1049 ms 101964 KB Output is correct
81 Correct 1042 ms 101960 KB Output is correct
82 Correct 1043 ms 101996 KB Output is correct
83 Correct 1112 ms 101912 KB Output is correct
84 Correct 1035 ms 101908 KB Output is correct
85 Correct 1078 ms 101916 KB Output is correct
86 Correct 1089 ms 101928 KB Output is correct
87 Correct 1035 ms 101952 KB Output is correct
88 Correct 1014 ms 102000 KB Output is correct
89 Correct 1039 ms 101952 KB Output is correct
90 Correct 1067 ms 101912 KB Output is correct
91 Correct 1020 ms 101912 KB Output is correct
92 Correct 1042 ms 102000 KB Output is correct
93 Correct 1084 ms 101912 KB Output is correct
94 Correct 1104 ms 101984 KB Output is correct
95 Correct 1036 ms 102044 KB Output is correct
96 Correct 1088 ms 101912 KB Output is correct
97 Correct 1037 ms 101912 KB Output is correct
98 Correct 1020 ms 101936 KB Output is correct
99 Correct 1014 ms 102016 KB Output is correct
100 Correct 813 ms 101908 KB Output is correct
101 Correct 827 ms 101928 KB Output is correct
102 Correct 813 ms 101908 KB Output is correct
103 Correct 814 ms 101912 KB Output is correct
104 Correct 838 ms 101916 KB Output is correct
105 Correct 888 ms 101916 KB Output is correct
106 Correct 849 ms 101912 KB Output is correct
107 Correct 877 ms 101904 KB Output is correct
108 Correct 875 ms 101908 KB Output is correct
109 Correct 862 ms 101928 KB Output is correct
110 Correct 984 ms 101912 KB Output is correct
111 Correct 972 ms 101932 KB Output is correct
112 Correct 995 ms 101908 KB Output is correct
113 Correct 1024 ms 101952 KB Output is correct
114 Correct 945 ms 101944 KB Output is correct
115 Correct 991 ms 101908 KB Output is correct
116 Correct 982 ms 102016 KB Output is correct
117 Correct 990 ms 101908 KB Output is correct
118 Correct 1070 ms 101908 KB Output is correct
119 Correct 1029 ms 101912 KB Output is correct
120 Correct 0 ms 340 KB Output is correct
121 Correct 0 ms 340 KB Output is correct
122 Correct 1057 ms 101916 KB Output is correct
123 Correct 1067 ms 101912 KB Output is correct
124 Correct 1016 ms 101984 KB Output is correct
125 Correct 1050 ms 102024 KB Output is correct
126 Correct 964 ms 102064 KB Output is correct
127 Correct 1043 ms 102012 KB Output is correct
128 Correct 1031 ms 101936 KB Output is correct
129 Correct 1020 ms 101992 KB Output is correct
130 Correct 975 ms 101916 KB Output is correct
131 Correct 975 ms 101908 KB Output is correct
132 Correct 1020 ms 101960 KB Output is correct
133 Correct 1032 ms 102024 KB Output is correct