Submission #206115

# Submission time Handle Problem Language Result Execution time Memory
206115 2020-03-02T09:29:12 Z TAISA_ Bulldozer (JOI17_bulldozer) C++14
100 / 100
1757 ms 68908 KB
#include <bits/stdc++.h>
#define all(v) v.begin(),v.end()
#define eb emplace_back
using namespace std;
using ll=long long;
using P=pair<int,int>;
using C=complex<double>;
void chmax(ll &a,ll b){a=max(a,b);}
void chmin(ll &a,ll b){a=min(a,b);}
struct segtree{
	struct T{
		ll l,r,sum,val;
	};
	T merge(T &a,T &b){
		T res;
		res.l=max(a.l,a.sum+b.l);
		res.r=max(b.r,a.r+b.sum);
		res.sum=a.sum+b.sum;
		res.val=max({a.val,b.val,a.r+b.l});
		return res;
	}
	int n;
	vector<T> dat;
	segtree(int n_){
		n=1;
		while(n<n_)n<<=1;
		dat.resize(2*n,T{0,0,0,0});
	}
	void upd(int k,ll x){
		T to=T{max(x,0LL),max(x,0LL),x,max(x,0LL)};
		k+=n;
		dat[k]=to;
		k>>=1;
		while(k>0){
			dat[k]=merge(dat[k<<1],dat[k<<1|1]);
			k>>=1;
		}
	}
	inline ll get(){
		return dat[1].val;
	}
};
const long double eps=1e-50;
bool equal(long double a,long double b){return a-eps<=b&&b<=a+eps;}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;cin>>n;
	vector<long double> x(n),y(n);
	vector<ll> w(n);
	vector<pair<long double,P>> v;
	vector<pair<P,int>> ps(n);
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i]>>w[i];
		ps[i]=make_pair(P(y[i],x[i]),i);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j)continue;
			long double t=atan2l(y[j]-y[i],x[j]-x[i]);
			if(t>=0){
				v.eb(t,P(i,j));
			}
		}
	}
	sort(all(v));
	sort(all(ps));
	reverse(all(ps));
	segtree seg(n);
	vector<int> pos(n),a(n);
	for(int i=0;i<n;i++){
		seg.upd(i,w[ps[i].second]);
		pos[ps[i].second]=i;
		a[i]=ps[i].second;
	}
	ll res=seg.get();
	vector<vector<int>> G(n);
	vector<int> in(n);
	set<int> st;
	for(int i=0;i<v.size();i++){
		int l=v[i].second.first,r=v[i].second.second;
		G[l].eb(r);
		in[r]++;
		st.insert(l);
		st.insert(r);
		if(i+1<v.size()&&equal(v[i].first,v[i+1].first))continue;
		vector<int> rt;
		for(auto &e:st){
			if(in[e]==0)rt.eb(e);
		}
		for(auto &ro:rt){
			int id=ro;
			vector<int> vs;
			vs.eb(ro);
			while(!G[id].empty()){
				int to;
				for(auto &e:G[id]){
					in[e]--;
					if(in[e]==0){
						to=e;
					}
				}
				vs.eb(to);
				id=to;
			}
			int sz=vs.size();
			for(int j=0;j<sz;j++){
				if(sz-j-1<=j)break;
				int a=vs[j],b=vs[sz-j-1];
				swap(pos[a],pos[b]);
				seg.upd(pos[a],w[a]);
				seg.upd(pos[b],w[b]);
			}
		}
		for(auto &e:st){
			in[e]=0;
			G[e].clear();
		}
		st.clear();
		chmax(res,seg.get());
	}
	cout<<res<<'\n';
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:80:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v.size();i++){
              ~^~~~~~~~~
bulldozer.cpp:86:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i+1<v.size()&&equal(v[i].first,v[i+1].first))continue;
      ~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1016 KB Output is correct
2 Correct 8 ms 1016 KB Output is correct
3 Correct 8 ms 1016 KB Output is correct
4 Correct 8 ms 1016 KB Output is correct
5 Correct 8 ms 1016 KB Output is correct
6 Correct 7 ms 1016 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 8 ms 1016 KB Output is correct
9 Correct 8 ms 1016 KB Output is correct
10 Correct 8 ms 1016 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 764 KB Output is correct
2 Correct 8 ms 760 KB Output is correct
3 Correct 9 ms 760 KB Output is correct
4 Correct 8 ms 760 KB Output is correct
5 Correct 8 ms 760 KB Output is correct
6 Correct 8 ms 760 KB Output is correct
7 Correct 9 ms 760 KB Output is correct
8 Correct 8 ms 760 KB Output is correct
9 Correct 9 ms 760 KB Output is correct
10 Correct 8 ms 760 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 380 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 380 KB Output is correct
21 Correct 9 ms 812 KB Output is correct
22 Correct 8 ms 760 KB Output is correct
23 Correct 8 ms 760 KB Output is correct
24 Correct 9 ms 760 KB Output is correct
25 Correct 9 ms 760 KB Output is correct
26 Correct 8 ms 760 KB Output is correct
27 Correct 8 ms 760 KB Output is correct
28 Correct 8 ms 760 KB Output is correct
29 Correct 8 ms 760 KB Output is correct
30 Correct 8 ms 760 KB Output is correct
31 Correct 9 ms 760 KB Output is correct
32 Correct 9 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 764 KB Output is correct
2 Correct 8 ms 760 KB Output is correct
3 Correct 9 ms 760 KB Output is correct
4 Correct 8 ms 760 KB Output is correct
5 Correct 8 ms 760 KB Output is correct
6 Correct 8 ms 760 KB Output is correct
7 Correct 9 ms 760 KB Output is correct
8 Correct 8 ms 760 KB Output is correct
9 Correct 9 ms 760 KB Output is correct
10 Correct 8 ms 760 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 380 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 380 KB Output is correct
21 Correct 9 ms 812 KB Output is correct
22 Correct 8 ms 760 KB Output is correct
23 Correct 8 ms 760 KB Output is correct
24 Correct 9 ms 760 KB Output is correct
25 Correct 9 ms 760 KB Output is correct
26 Correct 8 ms 760 KB Output is correct
27 Correct 8 ms 760 KB Output is correct
28 Correct 8 ms 760 KB Output is correct
29 Correct 8 ms 760 KB Output is correct
30 Correct 8 ms 760 KB Output is correct
31 Correct 9 ms 760 KB Output is correct
32 Correct 9 ms 760 KB Output is correct
33 Correct 1749 ms 66200 KB Output is correct
34 Correct 1724 ms 66200 KB Output is correct
35 Correct 1705 ms 66200 KB Output is correct
36 Correct 1706 ms 66200 KB Output is correct
37 Correct 1715 ms 66328 KB Output is correct
38 Correct 1744 ms 66356 KB Output is correct
39 Correct 1725 ms 66340 KB Output is correct
40 Correct 1724 ms 66200 KB Output is correct
41 Correct 1724 ms 66200 KB Output is correct
42 Correct 1704 ms 66264 KB Output is correct
43 Correct 1686 ms 66200 KB Output is correct
44 Correct 1676 ms 66344 KB Output is correct
45 Correct 1671 ms 66456 KB Output is correct
46 Correct 1665 ms 66204 KB Output is correct
47 Correct 1660 ms 66200 KB Output is correct
48 Correct 1694 ms 66328 KB Output is correct
49 Correct 1690 ms 66200 KB Output is correct
50 Correct 1692 ms 66200 KB Output is correct
51 Correct 1667 ms 66200 KB Output is correct
52 Correct 1663 ms 66200 KB Output is correct
53 Correct 1682 ms 66328 KB Output is correct
54 Correct 1656 ms 66328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 764 KB Output is correct
2 Correct 8 ms 760 KB Output is correct
3 Correct 9 ms 760 KB Output is correct
4 Correct 8 ms 760 KB Output is correct
5 Correct 8 ms 760 KB Output is correct
6 Correct 8 ms 760 KB Output is correct
7 Correct 9 ms 760 KB Output is correct
8 Correct 8 ms 760 KB Output is correct
9 Correct 9 ms 760 KB Output is correct
10 Correct 8 ms 760 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 380 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 380 KB Output is correct
21 Correct 9 ms 812 KB Output is correct
22 Correct 8 ms 760 KB Output is correct
23 Correct 8 ms 760 KB Output is correct
24 Correct 9 ms 760 KB Output is correct
25 Correct 9 ms 760 KB Output is correct
26 Correct 8 ms 760 KB Output is correct
27 Correct 8 ms 760 KB Output is correct
28 Correct 8 ms 760 KB Output is correct
29 Correct 8 ms 760 KB Output is correct
30 Correct 8 ms 760 KB Output is correct
31 Correct 9 ms 760 KB Output is correct
32 Correct 9 ms 760 KB Output is correct
33 Correct 1749 ms 66200 KB Output is correct
34 Correct 1724 ms 66200 KB Output is correct
35 Correct 1705 ms 66200 KB Output is correct
36 Correct 1706 ms 66200 KB Output is correct
37 Correct 1715 ms 66328 KB Output is correct
38 Correct 1744 ms 66356 KB Output is correct
39 Correct 1725 ms 66340 KB Output is correct
40 Correct 1724 ms 66200 KB Output is correct
41 Correct 1724 ms 66200 KB Output is correct
42 Correct 1704 ms 66264 KB Output is correct
43 Correct 1686 ms 66200 KB Output is correct
44 Correct 1676 ms 66344 KB Output is correct
45 Correct 1671 ms 66456 KB Output is correct
46 Correct 1665 ms 66204 KB Output is correct
47 Correct 1660 ms 66200 KB Output is correct
48 Correct 1694 ms 66328 KB Output is correct
49 Correct 1690 ms 66200 KB Output is correct
50 Correct 1692 ms 66200 KB Output is correct
51 Correct 1667 ms 66200 KB Output is correct
52 Correct 1663 ms 66200 KB Output is correct
53 Correct 1682 ms 66328 KB Output is correct
54 Correct 1656 ms 66328 KB Output is correct
55 Correct 1709 ms 66220 KB Output is correct
56 Correct 1703 ms 66072 KB Output is correct
57 Correct 1700 ms 66200 KB Output is correct
58 Correct 1706 ms 66204 KB Output is correct
59 Correct 1697 ms 66292 KB Output is correct
60 Correct 1713 ms 66328 KB Output is correct
61 Correct 1739 ms 66200 KB Output is correct
62 Correct 1713 ms 66200 KB Output is correct
63 Correct 1712 ms 66200 KB Output is correct
64 Correct 1710 ms 66200 KB Output is correct
65 Correct 1703 ms 66328 KB Output is correct
66 Correct 1690 ms 66644 KB Output is correct
67 Correct 1687 ms 66332 KB Output is correct
68 Correct 1695 ms 66332 KB Output is correct
69 Correct 1712 ms 66328 KB Output is correct
70 Correct 1678 ms 66328 KB Output is correct
71 Correct 1695 ms 66328 KB Output is correct
72 Correct 1687 ms 66456 KB Output is correct
73 Correct 1715 ms 66256 KB Output is correct
74 Correct 1691 ms 66644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1016 KB Output is correct
2 Correct 8 ms 1016 KB Output is correct
3 Correct 8 ms 1016 KB Output is correct
4 Correct 8 ms 1016 KB Output is correct
5 Correct 8 ms 1016 KB Output is correct
6 Correct 7 ms 1016 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 8 ms 1016 KB Output is correct
9 Correct 8 ms 1016 KB Output is correct
10 Correct 8 ms 1016 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 9 ms 764 KB Output is correct
17 Correct 8 ms 760 KB Output is correct
18 Correct 9 ms 760 KB Output is correct
19 Correct 8 ms 760 KB Output is correct
20 Correct 8 ms 760 KB Output is correct
21 Correct 8 ms 760 KB Output is correct
22 Correct 9 ms 760 KB Output is correct
23 Correct 8 ms 760 KB Output is correct
24 Correct 9 ms 760 KB Output is correct
25 Correct 8 ms 760 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 380 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 380 KB Output is correct
36 Correct 9 ms 812 KB Output is correct
37 Correct 8 ms 760 KB Output is correct
38 Correct 8 ms 760 KB Output is correct
39 Correct 9 ms 760 KB Output is correct
40 Correct 9 ms 760 KB Output is correct
41 Correct 8 ms 760 KB Output is correct
42 Correct 8 ms 760 KB Output is correct
43 Correct 8 ms 760 KB Output is correct
44 Correct 8 ms 760 KB Output is correct
45 Correct 8 ms 760 KB Output is correct
46 Correct 9 ms 760 KB Output is correct
47 Correct 9 ms 760 KB Output is correct
48 Correct 1749 ms 66200 KB Output is correct
49 Correct 1724 ms 66200 KB Output is correct
50 Correct 1705 ms 66200 KB Output is correct
51 Correct 1706 ms 66200 KB Output is correct
52 Correct 1715 ms 66328 KB Output is correct
53 Correct 1744 ms 66356 KB Output is correct
54 Correct 1725 ms 66340 KB Output is correct
55 Correct 1724 ms 66200 KB Output is correct
56 Correct 1724 ms 66200 KB Output is correct
57 Correct 1704 ms 66264 KB Output is correct
58 Correct 1686 ms 66200 KB Output is correct
59 Correct 1676 ms 66344 KB Output is correct
60 Correct 1671 ms 66456 KB Output is correct
61 Correct 1665 ms 66204 KB Output is correct
62 Correct 1660 ms 66200 KB Output is correct
63 Correct 1694 ms 66328 KB Output is correct
64 Correct 1690 ms 66200 KB Output is correct
65 Correct 1692 ms 66200 KB Output is correct
66 Correct 1667 ms 66200 KB Output is correct
67 Correct 1663 ms 66200 KB Output is correct
68 Correct 1682 ms 66328 KB Output is correct
69 Correct 1656 ms 66328 KB Output is correct
70 Correct 1709 ms 66220 KB Output is correct
71 Correct 1703 ms 66072 KB Output is correct
72 Correct 1700 ms 66200 KB Output is correct
73 Correct 1706 ms 66204 KB Output is correct
74 Correct 1697 ms 66292 KB Output is correct
75 Correct 1713 ms 66328 KB Output is correct
76 Correct 1739 ms 66200 KB Output is correct
77 Correct 1713 ms 66200 KB Output is correct
78 Correct 1712 ms 66200 KB Output is correct
79 Correct 1710 ms 66200 KB Output is correct
80 Correct 1703 ms 66328 KB Output is correct
81 Correct 1690 ms 66644 KB Output is correct
82 Correct 1687 ms 66332 KB Output is correct
83 Correct 1695 ms 66332 KB Output is correct
84 Correct 1712 ms 66328 KB Output is correct
85 Correct 1678 ms 66328 KB Output is correct
86 Correct 1695 ms 66328 KB Output is correct
87 Correct 1687 ms 66456 KB Output is correct
88 Correct 1715 ms 66256 KB Output is correct
89 Correct 1691 ms 66644 KB Output is correct
90 Correct 1720 ms 66456 KB Output is correct
91 Correct 1729 ms 66328 KB Output is correct
92 Correct 1732 ms 66584 KB Output is correct
93 Correct 1704 ms 66328 KB Output is correct
94 Correct 1718 ms 66328 KB Output is correct
95 Correct 1730 ms 66328 KB Output is correct
96 Correct 1696 ms 66328 KB Output is correct
97 Correct 1736 ms 66332 KB Output is correct
98 Correct 1718 ms 66544 KB Output is correct
99 Correct 1724 ms 66328 KB Output is correct
100 Correct 1327 ms 68860 KB Output is correct
101 Correct 1301 ms 68820 KB Output is correct
102 Correct 1312 ms 68908 KB Output is correct
103 Correct 1329 ms 68852 KB Output is correct
104 Correct 1339 ms 68812 KB Output is correct
105 Correct 1441 ms 67568 KB Output is correct
106 Correct 1458 ms 67412 KB Output is correct
107 Correct 1479 ms 67576 KB Output is correct
108 Correct 1471 ms 67540 KB Output is correct
109 Correct 1455 ms 67412 KB Output is correct
110 Correct 1608 ms 66456 KB Output is correct
111 Correct 1604 ms 66328 KB Output is correct
112 Correct 1592 ms 66328 KB Output is correct
113 Correct 1605 ms 66488 KB Output is correct
114 Correct 1618 ms 66328 KB Output is correct
115 Correct 1601 ms 66328 KB Output is correct
116 Correct 1610 ms 66328 KB Output is correct
117 Correct 1615 ms 66328 KB Output is correct
118 Correct 1620 ms 66328 KB Output is correct
119 Correct 1614 ms 66328 KB Output is correct
120 Correct 5 ms 376 KB Output is correct
121 Correct 5 ms 376 KB Output is correct
122 Correct 1757 ms 66328 KB Output is correct
123 Correct 1740 ms 66412 KB Output is correct
124 Correct 1740 ms 66328 KB Output is correct
125 Correct 1726 ms 66556 KB Output is correct
126 Correct 1726 ms 66544 KB Output is correct
127 Correct 1750 ms 66328 KB Output is correct
128 Correct 1741 ms 66328 KB Output is correct
129 Correct 1724 ms 66328 KB Output is correct
130 Correct 1701 ms 66328 KB Output is correct
131 Correct 1694 ms 66540 KB Output is correct
132 Correct 1668 ms 66328 KB Output is correct
133 Correct 1697 ms 66288 KB Output is correct