답안 #77366

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
77366 2018-09-26T13:18:54 Z tmwilliamlin168 Bulldozer (JOI17_bulldozer) C++14
100 / 100
937 ms 94564 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int mxN=2e3;
int n, p[mxN], l[mxN];
ll x[mxN], y[mxN], w[mxN], ans;
array<ll, 4> st[1<<12];
array<ll, 6> ss[mxN*(mxN-1)/2];

void upd(int l1, ll x, int i=1, int l2=0, int r2=n-1) {
	if(l2==r2) {
		st[i]={x, max(x, 0ll), max(x, 0ll), max(x, 0ll)};
		return;
	}
	int m2=(l2+r2)/2;
	if(l1<=m2)
		upd(l1, x, 2*i, l2, m2);
	else
		upd(l1, x, 2*i+1, m2+1, r2);
	st[i]={st[2*i][0]+st[2*i+1][0], max(st[2*i][1], st[2*i][0]+st[2*i+1][1]), max(st[2*i+1][2], st[2*i+1][0]+st[2*i][2]), max({st[2*i][3], st[2*i+1][3], st[2*i][2]+st[2*i+1][1]})};
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i=0; i<n; ++i) {
		cin >> x[i] >> y[i] >> w[i];
		p[i]=i;
	}
	for(int i=0, k=0; i<n; ++i)
		for(int j=0; j<n; ++j)
			if(i!=j&&(x[i]<x[j]||x[i]==x[j]&&y[i]>y[j]))
				ss[k++]={y[j]-y[i], x[j]-x[i], x[i]==x[j]?y[j]:-x[j], x[i]==x[j]?y[i]:-x[i], i, j};
	sort(p, p+n, [&](const int &a, const int b) {
		return x[a]==x[b]?y[a]>y[b]:x[a]<x[b];
	});
	for(int i=0; i<n; ++i) {
		upd(i, w[p[i]]);
		l[p[i]]=i;
	}
	sort(ss, ss+n*(n-1)/2, [&](const array<ll, 6> &a, const array<ll, 6> &b) {
		ll c=a[0]*b[1]-a[1]*b[0];
		return c?c<0:array<ll, 2>{a[2], a[3]}<array<ll, 2>{b[2], b[3]};
	});
	ans=st[1][3];
	for(int i=0; i<n*(n-1)/2; ++i) {
		int u=ss[i][4], v=ss[i][5];
		swap(l[u], l[v]);
		upd(l[u], w[u]);
		upd(l[v], w[v]);
		if(i>=n*(n-1)/2-1||ss[i][0]*ss[i+1][1]<ss[i][1]*ss[i+1][0])
			ans=max(st[1][3], ans);
	}
	cout << ans;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:36:35: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    if(i!=j&&(x[i]<x[j]||x[i]==x[j]&&y[i]>y[j]))
                         ~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 3 ms 664 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 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 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 3 ms 640 KB Output is correct
26 Correct 3 ms 640 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 3 ms 640 KB Output is correct
29 Correct 3 ms 640 KB Output is correct
30 Correct 3 ms 640 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 3 ms 664 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 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 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 3 ms 640 KB Output is correct
26 Correct 3 ms 640 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 3 ms 640 KB Output is correct
29 Correct 3 ms 640 KB Output is correct
30 Correct 3 ms 640 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 3 ms 640 KB Output is correct
33 Correct 850 ms 94460 KB Output is correct
34 Correct 859 ms 94452 KB Output is correct
35 Correct 871 ms 94468 KB Output is correct
36 Correct 884 ms 94456 KB Output is correct
37 Correct 860 ms 94456 KB Output is correct
38 Correct 849 ms 94452 KB Output is correct
39 Correct 837 ms 94464 KB Output is correct
40 Correct 838 ms 94456 KB Output is correct
41 Correct 862 ms 94456 KB Output is correct
42 Correct 871 ms 94456 KB Output is correct
43 Correct 823 ms 94456 KB Output is correct
44 Correct 840 ms 94460 KB Output is correct
45 Correct 823 ms 94512 KB Output is correct
46 Correct 820 ms 94524 KB Output is correct
47 Correct 819 ms 94456 KB Output is correct
48 Correct 826 ms 94456 KB Output is correct
49 Correct 817 ms 94460 KB Output is correct
50 Correct 827 ms 94456 KB Output is correct
51 Correct 836 ms 94532 KB Output is correct
52 Correct 841 ms 94456 KB Output is correct
53 Correct 823 ms 94452 KB Output is correct
54 Correct 822 ms 94456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 3 ms 664 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 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 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 3 ms 640 KB Output is correct
26 Correct 3 ms 640 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 3 ms 640 KB Output is correct
29 Correct 3 ms 640 KB Output is correct
30 Correct 3 ms 640 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 3 ms 640 KB Output is correct
33 Correct 850 ms 94460 KB Output is correct
34 Correct 859 ms 94452 KB Output is correct
35 Correct 871 ms 94468 KB Output is correct
36 Correct 884 ms 94456 KB Output is correct
37 Correct 860 ms 94456 KB Output is correct
38 Correct 849 ms 94452 KB Output is correct
39 Correct 837 ms 94464 KB Output is correct
40 Correct 838 ms 94456 KB Output is correct
41 Correct 862 ms 94456 KB Output is correct
42 Correct 871 ms 94456 KB Output is correct
43 Correct 823 ms 94456 KB Output is correct
44 Correct 840 ms 94460 KB Output is correct
45 Correct 823 ms 94512 KB Output is correct
46 Correct 820 ms 94524 KB Output is correct
47 Correct 819 ms 94456 KB Output is correct
48 Correct 826 ms 94456 KB Output is correct
49 Correct 817 ms 94460 KB Output is correct
50 Correct 827 ms 94456 KB Output is correct
51 Correct 836 ms 94532 KB Output is correct
52 Correct 841 ms 94456 KB Output is correct
53 Correct 823 ms 94452 KB Output is correct
54 Correct 822 ms 94456 KB Output is correct
55 Correct 838 ms 94460 KB Output is correct
56 Correct 848 ms 94452 KB Output is correct
57 Correct 859 ms 94468 KB Output is correct
58 Correct 854 ms 94464 KB Output is correct
59 Correct 855 ms 94456 KB Output is correct
60 Correct 829 ms 94460 KB Output is correct
61 Correct 827 ms 94464 KB Output is correct
62 Correct 828 ms 94456 KB Output is correct
63 Correct 821 ms 94456 KB Output is correct
64 Correct 849 ms 94460 KB Output is correct
65 Correct 850 ms 94456 KB Output is correct
66 Correct 842 ms 94452 KB Output is correct
67 Correct 865 ms 94464 KB Output is correct
68 Correct 846 ms 94456 KB Output is correct
69 Correct 830 ms 94460 KB Output is correct
70 Correct 826 ms 94456 KB Output is correct
71 Correct 859 ms 94428 KB Output is correct
72 Correct 856 ms 94452 KB Output is correct
73 Correct 843 ms 94468 KB Output is correct
74 Correct 837 ms 94468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 640 KB Output is correct
17 Correct 3 ms 640 KB Output is correct
18 Correct 3 ms 640 KB Output is correct
19 Correct 4 ms 640 KB Output is correct
20 Correct 3 ms 640 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 3 ms 664 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 3 ms 640 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 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 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 3 ms 640 KB Output is correct
37 Correct 3 ms 640 KB Output is correct
38 Correct 3 ms 640 KB Output is correct
39 Correct 3 ms 640 KB Output is correct
40 Correct 3 ms 640 KB Output is correct
41 Correct 3 ms 640 KB Output is correct
42 Correct 3 ms 640 KB Output is correct
43 Correct 3 ms 640 KB Output is correct
44 Correct 3 ms 640 KB Output is correct
45 Correct 3 ms 640 KB Output is correct
46 Correct 3 ms 640 KB Output is correct
47 Correct 3 ms 640 KB Output is correct
48 Correct 850 ms 94460 KB Output is correct
49 Correct 859 ms 94452 KB Output is correct
50 Correct 871 ms 94468 KB Output is correct
51 Correct 884 ms 94456 KB Output is correct
52 Correct 860 ms 94456 KB Output is correct
53 Correct 849 ms 94452 KB Output is correct
54 Correct 837 ms 94464 KB Output is correct
55 Correct 838 ms 94456 KB Output is correct
56 Correct 862 ms 94456 KB Output is correct
57 Correct 871 ms 94456 KB Output is correct
58 Correct 823 ms 94456 KB Output is correct
59 Correct 840 ms 94460 KB Output is correct
60 Correct 823 ms 94512 KB Output is correct
61 Correct 820 ms 94524 KB Output is correct
62 Correct 819 ms 94456 KB Output is correct
63 Correct 826 ms 94456 KB Output is correct
64 Correct 817 ms 94460 KB Output is correct
65 Correct 827 ms 94456 KB Output is correct
66 Correct 836 ms 94532 KB Output is correct
67 Correct 841 ms 94456 KB Output is correct
68 Correct 823 ms 94452 KB Output is correct
69 Correct 822 ms 94456 KB Output is correct
70 Correct 838 ms 94460 KB Output is correct
71 Correct 848 ms 94452 KB Output is correct
72 Correct 859 ms 94468 KB Output is correct
73 Correct 854 ms 94464 KB Output is correct
74 Correct 855 ms 94456 KB Output is correct
75 Correct 829 ms 94460 KB Output is correct
76 Correct 827 ms 94464 KB Output is correct
77 Correct 828 ms 94456 KB Output is correct
78 Correct 821 ms 94456 KB Output is correct
79 Correct 849 ms 94460 KB Output is correct
80 Correct 850 ms 94456 KB Output is correct
81 Correct 842 ms 94452 KB Output is correct
82 Correct 865 ms 94464 KB Output is correct
83 Correct 846 ms 94456 KB Output is correct
84 Correct 830 ms 94460 KB Output is correct
85 Correct 826 ms 94456 KB Output is correct
86 Correct 859 ms 94428 KB Output is correct
87 Correct 856 ms 94452 KB Output is correct
88 Correct 843 ms 94468 KB Output is correct
89 Correct 837 ms 94468 KB Output is correct
90 Correct 861 ms 94464 KB Output is correct
91 Correct 858 ms 94504 KB Output is correct
92 Correct 840 ms 94460 KB Output is correct
93 Correct 852 ms 94452 KB Output is correct
94 Correct 848 ms 94452 KB Output is correct
95 Correct 854 ms 94480 KB Output is correct
96 Correct 823 ms 94452 KB Output is correct
97 Correct 853 ms 94456 KB Output is correct
98 Correct 831 ms 94456 KB Output is correct
99 Correct 853 ms 94460 KB Output is correct
100 Correct 842 ms 94460 KB Output is correct
101 Correct 819 ms 94452 KB Output is correct
102 Correct 808 ms 94456 KB Output is correct
103 Correct 808 ms 94452 KB Output is correct
104 Correct 831 ms 94456 KB Output is correct
105 Correct 854 ms 94452 KB Output is correct
106 Correct 847 ms 94468 KB Output is correct
107 Correct 937 ms 94460 KB Output is correct
108 Correct 831 ms 94464 KB Output is correct
109 Correct 846 ms 94468 KB Output is correct
110 Correct 819 ms 94460 KB Output is correct
111 Correct 792 ms 94460 KB Output is correct
112 Correct 831 ms 94456 KB Output is correct
113 Correct 786 ms 94460 KB Output is correct
114 Correct 792 ms 94452 KB Output is correct
115 Correct 827 ms 94456 KB Output is correct
116 Correct 787 ms 94456 KB Output is correct
117 Correct 794 ms 94456 KB Output is correct
118 Correct 799 ms 94452 KB Output is correct
119 Correct 823 ms 94456 KB Output is correct
120 Correct 2 ms 384 KB Output is correct
121 Correct 2 ms 384 KB Output is correct
122 Correct 870 ms 94456 KB Output is correct
123 Correct 832 ms 94456 KB Output is correct
124 Correct 836 ms 94508 KB Output is correct
125 Correct 827 ms 94496 KB Output is correct
126 Correct 840 ms 94460 KB Output is correct
127 Correct 826 ms 94456 KB Output is correct
128 Correct 897 ms 94456 KB Output is correct
129 Correct 833 ms 94452 KB Output is correct
130 Correct 856 ms 94456 KB Output is correct
131 Correct 835 ms 94564 KB Output is correct
132 Correct 819 ms 94456 KB Output is correct
133 Correct 830 ms 94452 KB Output is correct