답안 #206093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
206093 2020-03-02T09:07:33 Z TAISA_ Bulldozer (JOI17_bulldozer) C++14
5 / 100
41 ms 764 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>;
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 double eps=1e-9;
bool equal(double a,double b){return a-eps<=b&&b<=a+eps;}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;cin>>n;
	vector<double> x(n),y(n);
	vector<ll> w(n);
	vector<pair<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;
			double t=atan2(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);
	for(int i=0;i<n;i++){
		seg.upd(i,w[ps[i].second]);
		pos[ps[i].second]=i;
	}
	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;
			}
			for(int j=0;j<vs.size();j++){
				if((int)vs.size()-j-1<=j)break;
				int a=vs[j],b=vs[(int)vs.size()-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();
		}
		chmax(res,seg.get());
	}
	cout<<res<<'\n';
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:78:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v.size();i++){
              ~^~~~~~~~~
bulldozer.cpp:84: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;
      ~~~^~~~~~~~~
bulldozer.cpp:104:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<vs.size();j++){
                ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 760 KB Output is correct
2 Correct 7 ms 760 KB Output is correct
3 Correct 7 ms 760 KB Output is correct
4 Correct 7 ms 760 KB Output is correct
5 Correct 7 ms 760 KB Output is correct
6 Correct 7 ms 760 KB Output is correct
7 Correct 7 ms 764 KB Output is correct
8 Correct 7 ms 760 KB Output is correct
9 Correct 7 ms 760 KB Output is correct
10 Correct 7 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
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 632 KB Output is correct
2 Correct 38 ms 504 KB Output is correct
3 Correct 38 ms 632 KB Output is correct
4 Correct 41 ms 548 KB Output is correct
5 Correct 38 ms 504 KB Output is correct
6 Correct 38 ms 504 KB Output is correct
7 Correct 40 ms 600 KB Output is correct
8 Correct 38 ms 504 KB Output is correct
9 Correct 38 ms 504 KB Output is correct
10 Correct 40 ms 504 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 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Incorrect 33 ms 504 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 632 KB Output is correct
2 Correct 38 ms 504 KB Output is correct
3 Correct 38 ms 632 KB Output is correct
4 Correct 41 ms 548 KB Output is correct
5 Correct 38 ms 504 KB Output is correct
6 Correct 38 ms 504 KB Output is correct
7 Correct 40 ms 600 KB Output is correct
8 Correct 38 ms 504 KB Output is correct
9 Correct 38 ms 504 KB Output is correct
10 Correct 40 ms 504 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 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Incorrect 33 ms 504 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 632 KB Output is correct
2 Correct 38 ms 504 KB Output is correct
3 Correct 38 ms 632 KB Output is correct
4 Correct 41 ms 548 KB Output is correct
5 Correct 38 ms 504 KB Output is correct
6 Correct 38 ms 504 KB Output is correct
7 Correct 40 ms 600 KB Output is correct
8 Correct 38 ms 504 KB Output is correct
9 Correct 38 ms 504 KB Output is correct
10 Correct 40 ms 504 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 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Incorrect 33 ms 504 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 760 KB Output is correct
2 Correct 7 ms 760 KB Output is correct
3 Correct 7 ms 760 KB Output is correct
4 Correct 7 ms 760 KB Output is correct
5 Correct 7 ms 760 KB Output is correct
6 Correct 7 ms 760 KB Output is correct
7 Correct 7 ms 764 KB Output is correct
8 Correct 7 ms 760 KB Output is correct
9 Correct 7 ms 760 KB Output is correct
10 Correct 7 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 38 ms 632 KB Output is correct
17 Correct 38 ms 504 KB Output is correct
18 Correct 38 ms 632 KB Output is correct
19 Correct 41 ms 548 KB Output is correct
20 Correct 38 ms 504 KB Output is correct
21 Correct 38 ms 504 KB Output is correct
22 Correct 40 ms 600 KB Output is correct
23 Correct 38 ms 504 KB Output is correct
24 Correct 38 ms 504 KB Output is correct
25 Correct 40 ms 504 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 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Incorrect 33 ms 504 KB Output isn't correct
37 Halted 0 ms 0 KB -