답안 #26582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26582 2017-07-03T09:40:21 Z dwarn Bulldozer (JOI17_bulldozer) C++14
100 / 100
1209 ms 118008 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : (v))
#define sz(v) (int)(v).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

struct ST {
	int n;
	vector<ll> sum, mx, mn, ans;
	ST(int _n) : n(_n){
		while(__builtin_popcount(n) > 1) ++n;
		sum.resize(2*n);
		mn.resize(2*n);
		mx.resize(2*n);
		ans.resize(2*n);
	}
	void upd(ll dif, int pos){
		for(pos += n; pos; pos /= 2){
			sum[pos] += dif;
			mn[pos] = min(0LL, sum[pos]);
			ans[pos] = mx[pos] = max(0LL, sum[pos]);
			if(pos < n){
				mn[pos] = min(mn[pos], min(mn[2*pos], sum[2*pos]+mn[2*pos+1]));
				mx[pos] = max(mx[pos], max(mx[2*pos], sum[2*pos]+mx[2*pos+1]));

				ans[pos] = max(ans[pos], max(ans[2*pos],ans[2*pos+1]));
				ans[pos] = max(ans[pos], mx[2*pos+1]+sum[2*pos]-mn[2*pos]);
			}
		}
	}
};

int ren[int(4e6)];
vector<vi> ls[int(2e6+10)];
int pos[int(2e6+10)], xs[2000], ys[2000], zs[2000];

int main(){
	rep(i,0,2e6+10) pos[i] = -1;

	int n;
	scanf("%d",&n);

	rep(i,0,n) scanf("%d %d %d",xs+i,ys+i,zs+i);

	auto vec = [&](int i, int j){
		int dx = xs[i]-xs[j], dy = ys[i]-ys[j];
		int g = dy==0 ? dx : __gcd(dx, dy);
		dx /= g, dy /= g;
		if(dx<0 || (dx==0 && dy<0)){
			dx = -dx, dy = -dy;
		}
		return pii(dx,dy);
	};

	vi perm(n);
	rep(i,0,n) perm[i] = i;
	sort(all(perm), [&](int i, int j){
		return xs[i]<xs[j]||(xs[i]==xs[j] && ys[i]<ys[j]);
	});
	vi mynum(n);
	rep(i,0,n) mynum[perm[i]] = i;

	vector<pair<pii,pii>> pas(n*(n-1)/2);
	int ix = 0;
	rep(i,0,n) rep(j,0,i) pas[ix++] = {vec(perm[i],perm[j]), {perm[i],perm[j]}};
	stable_sort(all(pas), [&](const pair<pii,pii> &a, const pair<pii,pii> &b){
		return (ll)a.first.second*b.first.first-(ll)a.first.first*b.first.second>0;
	});

	ST tree(n);
	rep(i,0,n)
		tree.upd(zs[i], mynum[i]);
	ll ans = tree.ans[1];

	for(int l = 0, r = 0; l < sz(pas); l = r){
		while(r < sz(pas) && pas[l].first == pas[r].first) ++r;
		rep(k,l,r){
			int a = pas[k].second.first, b = pas[k].second.second;
			tree.upd(zs[a]-zs[b], mynum[b]);
			tree.upd(zs[b]-zs[a], mynum[a]);
			swap(mynum[a], mynum[b]);
		}
		ans = max(ans, tree.ans[1]);
	}

	printf("%lld\n",ans);
	exit(0);

}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
bulldozer.cpp:48:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  rep(i,0,n) scanf("%d %d %d",xs+i,ys+i,zs+i);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 55288 KB Output is correct
2 Correct 48 ms 55268 KB Output is correct
3 Correct 48 ms 55216 KB Output is correct
4 Correct 48 ms 55276 KB Output is correct
5 Correct 50 ms 55416 KB Output is correct
6 Correct 49 ms 55288 KB Output is correct
7 Correct 48 ms 55288 KB Output is correct
8 Correct 48 ms 55276 KB Output is correct
9 Correct 48 ms 55288 KB Output is correct
10 Correct 51 ms 55288 KB Output is correct
11 Correct 50 ms 55160 KB Output is correct
12 Correct 48 ms 55160 KB Output is correct
13 Correct 50 ms 55160 KB Output is correct
14 Correct 50 ms 55156 KB Output is correct
15 Correct 50 ms 55060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 55336 KB Output is correct
2 Correct 50 ms 55208 KB Output is correct
3 Correct 51 ms 55288 KB Output is correct
4 Correct 50 ms 55260 KB Output is correct
5 Correct 53 ms 55260 KB Output is correct
6 Correct 55 ms 55332 KB Output is correct
7 Correct 56 ms 55248 KB Output is correct
8 Correct 51 ms 55260 KB Output is correct
9 Correct 52 ms 55288 KB Output is correct
10 Correct 53 ms 55288 KB Output is correct
11 Correct 52 ms 55056 KB Output is correct
12 Correct 49 ms 55084 KB Output is correct
13 Correct 50 ms 55160 KB Output is correct
14 Correct 49 ms 55116 KB Output is correct
15 Correct 51 ms 55184 KB Output is correct
16 Correct 49 ms 55160 KB Output is correct
17 Correct 48 ms 55160 KB Output is correct
18 Correct 48 ms 55172 KB Output is correct
19 Correct 49 ms 55160 KB Output is correct
20 Correct 48 ms 55172 KB Output is correct
21 Correct 52 ms 55300 KB Output is correct
22 Correct 50 ms 55288 KB Output is correct
23 Correct 52 ms 55324 KB Output is correct
24 Correct 52 ms 55240 KB Output is correct
25 Correct 51 ms 55328 KB Output is correct
26 Correct 50 ms 55288 KB Output is correct
27 Correct 52 ms 55272 KB Output is correct
28 Correct 52 ms 55400 KB Output is correct
29 Correct 50 ms 55260 KB Output is correct
30 Correct 51 ms 55288 KB Output is correct
31 Correct 49 ms 55300 KB Output is correct
32 Correct 53 ms 55288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 55336 KB Output is correct
2 Correct 50 ms 55208 KB Output is correct
3 Correct 51 ms 55288 KB Output is correct
4 Correct 50 ms 55260 KB Output is correct
5 Correct 53 ms 55260 KB Output is correct
6 Correct 55 ms 55332 KB Output is correct
7 Correct 56 ms 55248 KB Output is correct
8 Correct 51 ms 55260 KB Output is correct
9 Correct 52 ms 55288 KB Output is correct
10 Correct 53 ms 55288 KB Output is correct
11 Correct 52 ms 55056 KB Output is correct
12 Correct 49 ms 55084 KB Output is correct
13 Correct 50 ms 55160 KB Output is correct
14 Correct 49 ms 55116 KB Output is correct
15 Correct 51 ms 55184 KB Output is correct
16 Correct 49 ms 55160 KB Output is correct
17 Correct 48 ms 55160 KB Output is correct
18 Correct 48 ms 55172 KB Output is correct
19 Correct 49 ms 55160 KB Output is correct
20 Correct 48 ms 55172 KB Output is correct
21 Correct 52 ms 55300 KB Output is correct
22 Correct 50 ms 55288 KB Output is correct
23 Correct 52 ms 55324 KB Output is correct
24 Correct 52 ms 55240 KB Output is correct
25 Correct 51 ms 55328 KB Output is correct
26 Correct 50 ms 55288 KB Output is correct
27 Correct 52 ms 55272 KB Output is correct
28 Correct 52 ms 55400 KB Output is correct
29 Correct 50 ms 55260 KB Output is correct
30 Correct 51 ms 55288 KB Output is correct
31 Correct 49 ms 55300 KB Output is correct
32 Correct 53 ms 55288 KB Output is correct
33 Correct 1117 ms 117736 KB Output is correct
34 Correct 1129 ms 117876 KB Output is correct
35 Correct 1129 ms 117752 KB Output is correct
36 Correct 1142 ms 117752 KB Output is correct
37 Correct 1135 ms 117792 KB Output is correct
38 Correct 1151 ms 117756 KB Output is correct
39 Correct 1121 ms 117880 KB Output is correct
40 Correct 1120 ms 117852 KB Output is correct
41 Correct 1124 ms 117880 KB Output is correct
42 Correct 1130 ms 117724 KB Output is correct
43 Correct 1092 ms 117800 KB Output is correct
44 Correct 1071 ms 117816 KB Output is correct
45 Correct 1055 ms 117752 KB Output is correct
46 Correct 1079 ms 117800 KB Output is correct
47 Correct 1064 ms 117880 KB Output is correct
48 Correct 1087 ms 117804 KB Output is correct
49 Correct 1131 ms 117804 KB Output is correct
50 Correct 1068 ms 117880 KB Output is correct
51 Correct 1085 ms 117980 KB Output is correct
52 Correct 1051 ms 117808 KB Output is correct
53 Correct 1056 ms 117804 KB Output is correct
54 Correct 1062 ms 117740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 55336 KB Output is correct
2 Correct 50 ms 55208 KB Output is correct
3 Correct 51 ms 55288 KB Output is correct
4 Correct 50 ms 55260 KB Output is correct
5 Correct 53 ms 55260 KB Output is correct
6 Correct 55 ms 55332 KB Output is correct
7 Correct 56 ms 55248 KB Output is correct
8 Correct 51 ms 55260 KB Output is correct
9 Correct 52 ms 55288 KB Output is correct
10 Correct 53 ms 55288 KB Output is correct
11 Correct 52 ms 55056 KB Output is correct
12 Correct 49 ms 55084 KB Output is correct
13 Correct 50 ms 55160 KB Output is correct
14 Correct 49 ms 55116 KB Output is correct
15 Correct 51 ms 55184 KB Output is correct
16 Correct 49 ms 55160 KB Output is correct
17 Correct 48 ms 55160 KB Output is correct
18 Correct 48 ms 55172 KB Output is correct
19 Correct 49 ms 55160 KB Output is correct
20 Correct 48 ms 55172 KB Output is correct
21 Correct 52 ms 55300 KB Output is correct
22 Correct 50 ms 55288 KB Output is correct
23 Correct 52 ms 55324 KB Output is correct
24 Correct 52 ms 55240 KB Output is correct
25 Correct 51 ms 55328 KB Output is correct
26 Correct 50 ms 55288 KB Output is correct
27 Correct 52 ms 55272 KB Output is correct
28 Correct 52 ms 55400 KB Output is correct
29 Correct 50 ms 55260 KB Output is correct
30 Correct 51 ms 55288 KB Output is correct
31 Correct 49 ms 55300 KB Output is correct
32 Correct 53 ms 55288 KB Output is correct
33 Correct 1117 ms 117736 KB Output is correct
34 Correct 1129 ms 117876 KB Output is correct
35 Correct 1129 ms 117752 KB Output is correct
36 Correct 1142 ms 117752 KB Output is correct
37 Correct 1135 ms 117792 KB Output is correct
38 Correct 1151 ms 117756 KB Output is correct
39 Correct 1121 ms 117880 KB Output is correct
40 Correct 1120 ms 117852 KB Output is correct
41 Correct 1124 ms 117880 KB Output is correct
42 Correct 1130 ms 117724 KB Output is correct
43 Correct 1092 ms 117800 KB Output is correct
44 Correct 1071 ms 117816 KB Output is correct
45 Correct 1055 ms 117752 KB Output is correct
46 Correct 1079 ms 117800 KB Output is correct
47 Correct 1064 ms 117880 KB Output is correct
48 Correct 1087 ms 117804 KB Output is correct
49 Correct 1131 ms 117804 KB Output is correct
50 Correct 1068 ms 117880 KB Output is correct
51 Correct 1085 ms 117980 KB Output is correct
52 Correct 1051 ms 117808 KB Output is correct
53 Correct 1056 ms 117804 KB Output is correct
54 Correct 1062 ms 117740 KB Output is correct
55 Correct 1132 ms 117800 KB Output is correct
56 Correct 1129 ms 117896 KB Output is correct
57 Correct 1135 ms 117880 KB Output is correct
58 Correct 1138 ms 117792 KB Output is correct
59 Correct 1133 ms 117752 KB Output is correct
60 Correct 1121 ms 117960 KB Output is correct
61 Correct 1138 ms 117868 KB Output is correct
62 Correct 1136 ms 117828 KB Output is correct
63 Correct 1126 ms 117756 KB Output is correct
64 Correct 1184 ms 117752 KB Output is correct
65 Correct 1157 ms 117904 KB Output is correct
66 Correct 1119 ms 117820 KB Output is correct
67 Correct 1165 ms 117740 KB Output is correct
68 Correct 1209 ms 117768 KB Output is correct
69 Correct 1177 ms 117748 KB Output is correct
70 Correct 1209 ms 117736 KB Output is correct
71 Correct 1132 ms 117880 KB Output is correct
72 Correct 1113 ms 117752 KB Output is correct
73 Correct 1142 ms 117752 KB Output is correct
74 Correct 1134 ms 117752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 55288 KB Output is correct
2 Correct 48 ms 55268 KB Output is correct
3 Correct 48 ms 55216 KB Output is correct
4 Correct 48 ms 55276 KB Output is correct
5 Correct 50 ms 55416 KB Output is correct
6 Correct 49 ms 55288 KB Output is correct
7 Correct 48 ms 55288 KB Output is correct
8 Correct 48 ms 55276 KB Output is correct
9 Correct 48 ms 55288 KB Output is correct
10 Correct 51 ms 55288 KB Output is correct
11 Correct 50 ms 55160 KB Output is correct
12 Correct 48 ms 55160 KB Output is correct
13 Correct 50 ms 55160 KB Output is correct
14 Correct 50 ms 55156 KB Output is correct
15 Correct 50 ms 55060 KB Output is correct
16 Correct 55 ms 55336 KB Output is correct
17 Correct 50 ms 55208 KB Output is correct
18 Correct 51 ms 55288 KB Output is correct
19 Correct 50 ms 55260 KB Output is correct
20 Correct 53 ms 55260 KB Output is correct
21 Correct 55 ms 55332 KB Output is correct
22 Correct 56 ms 55248 KB Output is correct
23 Correct 51 ms 55260 KB Output is correct
24 Correct 52 ms 55288 KB Output is correct
25 Correct 53 ms 55288 KB Output is correct
26 Correct 52 ms 55056 KB Output is correct
27 Correct 49 ms 55084 KB Output is correct
28 Correct 50 ms 55160 KB Output is correct
29 Correct 49 ms 55116 KB Output is correct
30 Correct 51 ms 55184 KB Output is correct
31 Correct 49 ms 55160 KB Output is correct
32 Correct 48 ms 55160 KB Output is correct
33 Correct 48 ms 55172 KB Output is correct
34 Correct 49 ms 55160 KB Output is correct
35 Correct 48 ms 55172 KB Output is correct
36 Correct 52 ms 55300 KB Output is correct
37 Correct 50 ms 55288 KB Output is correct
38 Correct 52 ms 55324 KB Output is correct
39 Correct 52 ms 55240 KB Output is correct
40 Correct 51 ms 55328 KB Output is correct
41 Correct 50 ms 55288 KB Output is correct
42 Correct 52 ms 55272 KB Output is correct
43 Correct 52 ms 55400 KB Output is correct
44 Correct 50 ms 55260 KB Output is correct
45 Correct 51 ms 55288 KB Output is correct
46 Correct 49 ms 55300 KB Output is correct
47 Correct 53 ms 55288 KB Output is correct
48 Correct 1117 ms 117736 KB Output is correct
49 Correct 1129 ms 117876 KB Output is correct
50 Correct 1129 ms 117752 KB Output is correct
51 Correct 1142 ms 117752 KB Output is correct
52 Correct 1135 ms 117792 KB Output is correct
53 Correct 1151 ms 117756 KB Output is correct
54 Correct 1121 ms 117880 KB Output is correct
55 Correct 1120 ms 117852 KB Output is correct
56 Correct 1124 ms 117880 KB Output is correct
57 Correct 1130 ms 117724 KB Output is correct
58 Correct 1092 ms 117800 KB Output is correct
59 Correct 1071 ms 117816 KB Output is correct
60 Correct 1055 ms 117752 KB Output is correct
61 Correct 1079 ms 117800 KB Output is correct
62 Correct 1064 ms 117880 KB Output is correct
63 Correct 1087 ms 117804 KB Output is correct
64 Correct 1131 ms 117804 KB Output is correct
65 Correct 1068 ms 117880 KB Output is correct
66 Correct 1085 ms 117980 KB Output is correct
67 Correct 1051 ms 117808 KB Output is correct
68 Correct 1056 ms 117804 KB Output is correct
69 Correct 1062 ms 117740 KB Output is correct
70 Correct 1132 ms 117800 KB Output is correct
71 Correct 1129 ms 117896 KB Output is correct
72 Correct 1135 ms 117880 KB Output is correct
73 Correct 1138 ms 117792 KB Output is correct
74 Correct 1133 ms 117752 KB Output is correct
75 Correct 1121 ms 117960 KB Output is correct
76 Correct 1138 ms 117868 KB Output is correct
77 Correct 1136 ms 117828 KB Output is correct
78 Correct 1126 ms 117756 KB Output is correct
79 Correct 1184 ms 117752 KB Output is correct
80 Correct 1157 ms 117904 KB Output is correct
81 Correct 1119 ms 117820 KB Output is correct
82 Correct 1165 ms 117740 KB Output is correct
83 Correct 1209 ms 117768 KB Output is correct
84 Correct 1177 ms 117748 KB Output is correct
85 Correct 1209 ms 117736 KB Output is correct
86 Correct 1132 ms 117880 KB Output is correct
87 Correct 1113 ms 117752 KB Output is correct
88 Correct 1142 ms 117752 KB Output is correct
89 Correct 1134 ms 117752 KB Output is correct
90 Correct 1132 ms 117932 KB Output is correct
91 Correct 1128 ms 117880 KB Output is correct
92 Correct 1134 ms 117740 KB Output is correct
93 Correct 1124 ms 117812 KB Output is correct
94 Correct 1142 ms 117880 KB Output is correct
95 Correct 1129 ms 117880 KB Output is correct
96 Correct 1127 ms 117752 KB Output is correct
97 Correct 1126 ms 118008 KB Output is correct
98 Correct 1149 ms 117800 KB Output is correct
99 Correct 1129 ms 117740 KB Output is correct
100 Correct 753 ms 117868 KB Output is correct
101 Correct 739 ms 117804 KB Output is correct
102 Correct 739 ms 117748 KB Output is correct
103 Correct 720 ms 117728 KB Output is correct
104 Correct 722 ms 117804 KB Output is correct
105 Correct 741 ms 117828 KB Output is correct
106 Correct 774 ms 117808 KB Output is correct
107 Correct 740 ms 117872 KB Output is correct
108 Correct 739 ms 117812 KB Output is correct
109 Correct 745 ms 117792 KB Output is correct
110 Correct 832 ms 117744 KB Output is correct
111 Correct 857 ms 117876 KB Output is correct
112 Correct 871 ms 117804 KB Output is correct
113 Correct 854 ms 117896 KB Output is correct
114 Correct 889 ms 117740 KB Output is correct
115 Correct 833 ms 117724 KB Output is correct
116 Correct 846 ms 117752 KB Output is correct
117 Correct 839 ms 117880 KB Output is correct
118 Correct 892 ms 117984 KB Output is correct
119 Correct 834 ms 117752 KB Output is correct
120 Correct 54 ms 55160 KB Output is correct
121 Correct 52 ms 55160 KB Output is correct
122 Correct 935 ms 117824 KB Output is correct
123 Correct 990 ms 117752 KB Output is correct
124 Correct 941 ms 117832 KB Output is correct
125 Correct 931 ms 117828 KB Output is correct
126 Correct 975 ms 117768 KB Output is correct
127 Correct 977 ms 117832 KB Output is correct
128 Correct 979 ms 117880 KB Output is correct
129 Correct 966 ms 117880 KB Output is correct
130 Correct 981 ms 117880 KB Output is correct
131 Correct 1027 ms 117880 KB Output is correct
132 Correct 959 ms 117880 KB Output is correct
133 Correct 997 ms 117880 KB Output is correct