답안 #943343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
943343 2024-03-11T11:09:03 Z HIR180 Bulldozer (JOI17_bulldozer) C++17
100 / 100
516 ms 35520 KB
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rng(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,b) rng(i,0,b)
#define repn(i,b) rng(i,1,b+1)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define si(x) (int)(x.size())
#define mp make_pair

#define tct template<class t>
tct using vc=vector<t>;
using vi=vc<int>;
#define tctu template<class t,class u>
tctu bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
tctu bool chmin(t&a,u b){if(a>b){a=b;return true;}else return false;}

using P=pair<int,int>;
#define mp make_pair
#define a first
#define b second
using ld = long double;
constexpr int mod = 998244353;

void solve(){
	int n;cin>>n;
	vc<pair<P,int>>vec(n);
	rep(i,n){
		int x,y,w;cin>>x>>y>>w;
		vec[i] = mp(mp(x, y), w);
	}
	sort(all(vec), [](auto&a, auto&b){
		if(a.a.a != b.a.a) return a.a.a < b.a.a;
		return a.a.b < b.a.b;
	});
	vc<pair<P,P>>dir;
	rep(i,n){
		rng(j,i+1,n){
			if(vec[i].a.a == vec[j].a.a) continue;
			dir.eb(mp(vec[j].a.a-vec[i].a.a, vec[j].a.b-vec[i].a.b), mp(i, j));
		}
	}
	vc<int>p(n),ran(n);
	rep(i,n) p[i] = ran[i] = i;
	sort(all(dir), [](auto &a,auto &b){
		ll f = (ll)a.a.a*b.a.b-(ll)a.a.b*b.a.a;
		if(f) return f > 0;
		else return a.b < b.b;
	});
	int nn = 1;
	while(nn <= n) nn <<= 1;
	
	vc<ll>seg(2*nn), sum(2*nn), le(2*nn), ri(2*nn);
	auto mrg=[&](int k){
		sum[k] = sum[k*2+1]+sum[k*2+2];
		le[k] = max(le[k*2+1], sum[k*2+1]+le[k*2+2]);
		ri[k] = max(ri[k*2+2], sum[k*2+2]+ri[k*2+1]);
		seg[k] = max(max(seg[k*2+1],seg[k*2+2]),le[k*2+2]+ri[k*2+1]);
	};
	auto upd=[&](int pos, int v){
		pos += nn-1;
		sum[pos] = v;
		le[pos] = ri[pos] = seg[pos] = max(0, v);
		while(pos){
			pos = (pos-1)/2;
			mrg(pos);
		}
	};
	rep(i,n){
		upd(i, vec[p[i]].b);
	}
	ll ans = seg[0];
	rep(i,si(dir)){
		int x = dir[i].b.a, y = dir[i].b.b;
		if(ran[x] < ran[y]){
			swap(p[ran[x]], p[ran[y]]);
			swap(ran[x], ran[y]);
			upd(ran[x], vec[p[ran[x]]].b);
			upd(ran[y], vec[p[ran[y]]].b);
		}
		if(i+1 == si(dir) or (ll)dir[i].a.a*dir[i+1].a.b != (ll)dir[i].a.b*dir[i+1].a.a){
			chmax(ans, seg[0]);
		}
	}
	cout << ans << '\n';
		
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	int t; t=1;//cin>>t;
	while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 452 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 456 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 452 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 456 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 676 KB Output is correct
33 Correct 485 ms 34348 KB Output is correct
34 Correct 473 ms 33988 KB Output is correct
35 Correct 468 ms 33476 KB Output is correct
36 Correct 510 ms 33476 KB Output is correct
37 Correct 479 ms 34244 KB Output is correct
38 Correct 466 ms 33728 KB Output is correct
39 Correct 472 ms 35012 KB Output is correct
40 Correct 467 ms 33476 KB Output is correct
41 Correct 476 ms 33984 KB Output is correct
42 Correct 515 ms 34244 KB Output is correct
43 Correct 464 ms 33728 KB Output is correct
44 Correct 465 ms 34244 KB Output is correct
45 Correct 463 ms 33476 KB Output is correct
46 Correct 463 ms 34500 KB Output is correct
47 Correct 462 ms 33728 KB Output is correct
48 Correct 466 ms 33476 KB Output is correct
49 Correct 465 ms 34752 KB Output is correct
50 Correct 465 ms 34244 KB Output is correct
51 Correct 462 ms 34244 KB Output is correct
52 Correct 464 ms 33988 KB Output is correct
53 Correct 466 ms 34496 KB Output is correct
54 Correct 471 ms 34756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 452 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 456 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 676 KB Output is correct
33 Correct 485 ms 34348 KB Output is correct
34 Correct 473 ms 33988 KB Output is correct
35 Correct 468 ms 33476 KB Output is correct
36 Correct 510 ms 33476 KB Output is correct
37 Correct 479 ms 34244 KB Output is correct
38 Correct 466 ms 33728 KB Output is correct
39 Correct 472 ms 35012 KB Output is correct
40 Correct 467 ms 33476 KB Output is correct
41 Correct 476 ms 33984 KB Output is correct
42 Correct 515 ms 34244 KB Output is correct
43 Correct 464 ms 33728 KB Output is correct
44 Correct 465 ms 34244 KB Output is correct
45 Correct 463 ms 33476 KB Output is correct
46 Correct 463 ms 34500 KB Output is correct
47 Correct 462 ms 33728 KB Output is correct
48 Correct 466 ms 33476 KB Output is correct
49 Correct 465 ms 34752 KB Output is correct
50 Correct 465 ms 34244 KB Output is correct
51 Correct 462 ms 34244 KB Output is correct
52 Correct 464 ms 33988 KB Output is correct
53 Correct 466 ms 34496 KB Output is correct
54 Correct 471 ms 34756 KB Output is correct
55 Correct 473 ms 33472 KB Output is correct
56 Correct 467 ms 33728 KB Output is correct
57 Correct 480 ms 34108 KB Output is correct
58 Correct 476 ms 33728 KB Output is correct
59 Correct 468 ms 33984 KB Output is correct
60 Correct 477 ms 35252 KB Output is correct
61 Correct 482 ms 35268 KB Output is correct
62 Correct 467 ms 35264 KB Output is correct
63 Correct 502 ms 34748 KB Output is correct
64 Correct 467 ms 34500 KB Output is correct
65 Correct 466 ms 33728 KB Output is correct
66 Correct 468 ms 33728 KB Output is correct
67 Correct 465 ms 33728 KB Output is correct
68 Correct 472 ms 35464 KB Output is correct
69 Correct 484 ms 34500 KB Output is correct
70 Correct 516 ms 34500 KB Output is correct
71 Correct 467 ms 33732 KB Output is correct
72 Correct 483 ms 35008 KB Output is correct
73 Correct 470 ms 33476 KB Output is correct
74 Correct 466 ms 33476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 452 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 456 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 600 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 1 ms 676 KB Output is correct
48 Correct 485 ms 34348 KB Output is correct
49 Correct 473 ms 33988 KB Output is correct
50 Correct 468 ms 33476 KB Output is correct
51 Correct 510 ms 33476 KB Output is correct
52 Correct 479 ms 34244 KB Output is correct
53 Correct 466 ms 33728 KB Output is correct
54 Correct 472 ms 35012 KB Output is correct
55 Correct 467 ms 33476 KB Output is correct
56 Correct 476 ms 33984 KB Output is correct
57 Correct 515 ms 34244 KB Output is correct
58 Correct 464 ms 33728 KB Output is correct
59 Correct 465 ms 34244 KB Output is correct
60 Correct 463 ms 33476 KB Output is correct
61 Correct 463 ms 34500 KB Output is correct
62 Correct 462 ms 33728 KB Output is correct
63 Correct 466 ms 33476 KB Output is correct
64 Correct 465 ms 34752 KB Output is correct
65 Correct 465 ms 34244 KB Output is correct
66 Correct 462 ms 34244 KB Output is correct
67 Correct 464 ms 33988 KB Output is correct
68 Correct 466 ms 34496 KB Output is correct
69 Correct 471 ms 34756 KB Output is correct
70 Correct 473 ms 33472 KB Output is correct
71 Correct 467 ms 33728 KB Output is correct
72 Correct 480 ms 34108 KB Output is correct
73 Correct 476 ms 33728 KB Output is correct
74 Correct 468 ms 33984 KB Output is correct
75 Correct 477 ms 35252 KB Output is correct
76 Correct 482 ms 35268 KB Output is correct
77 Correct 467 ms 35264 KB Output is correct
78 Correct 502 ms 34748 KB Output is correct
79 Correct 467 ms 34500 KB Output is correct
80 Correct 466 ms 33728 KB Output is correct
81 Correct 468 ms 33728 KB Output is correct
82 Correct 465 ms 33728 KB Output is correct
83 Correct 472 ms 35464 KB Output is correct
84 Correct 484 ms 34500 KB Output is correct
85 Correct 516 ms 34500 KB Output is correct
86 Correct 467 ms 33732 KB Output is correct
87 Correct 483 ms 35008 KB Output is correct
88 Correct 470 ms 33476 KB Output is correct
89 Correct 466 ms 33476 KB Output is correct
90 Correct 471 ms 33732 KB Output is correct
91 Correct 474 ms 33732 KB Output is correct
92 Correct 478 ms 33728 KB Output is correct
93 Correct 469 ms 34756 KB Output is correct
94 Correct 475 ms 33728 KB Output is correct
95 Correct 481 ms 34240 KB Output is correct
96 Correct 466 ms 34240 KB Output is correct
97 Correct 474 ms 34500 KB Output is correct
98 Correct 464 ms 34496 KB Output is correct
99 Correct 475 ms 35008 KB Output is correct
100 Correct 206 ms 17608 KB Output is correct
101 Correct 211 ms 17864 KB Output is correct
102 Correct 238 ms 17784 KB Output is correct
103 Correct 206 ms 17608 KB Output is correct
104 Correct 215 ms 17608 KB Output is correct
105 Correct 283 ms 33728 KB Output is correct
106 Correct 284 ms 33472 KB Output is correct
107 Correct 284 ms 35012 KB Output is correct
108 Correct 303 ms 35520 KB Output is correct
109 Correct 282 ms 34244 KB Output is correct
110 Correct 443 ms 33988 KB Output is correct
111 Correct 449 ms 34500 KB Output is correct
112 Correct 464 ms 33728 KB Output is correct
113 Correct 465 ms 34092 KB Output is correct
114 Correct 458 ms 33956 KB Output is correct
115 Correct 485 ms 34496 KB Output is correct
116 Correct 455 ms 34240 KB Output is correct
117 Correct 455 ms 35264 KB Output is correct
118 Correct 445 ms 33732 KB Output is correct
119 Correct 448 ms 33732 KB Output is correct
120 Correct 0 ms 344 KB Output is correct
121 Correct 0 ms 348 KB Output is correct
122 Correct 472 ms 34388 KB Output is correct
123 Correct 475 ms 35264 KB Output is correct
124 Correct 478 ms 34884 KB Output is correct
125 Correct 473 ms 34820 KB Output is correct
126 Correct 472 ms 33472 KB Output is correct
127 Correct 470 ms 34752 KB Output is correct
128 Correct 465 ms 34500 KB Output is correct
129 Correct 466 ms 33728 KB Output is correct
130 Correct 472 ms 35264 KB Output is correct
131 Correct 467 ms 33476 KB Output is correct
132 Correct 475 ms 35008 KB Output is correct
133 Correct 459 ms 35264 KB Output is correct