답안 #151133

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151133 2019-09-01T20:28:38 Z TadijaSebez Bulldozer (JOI17_bulldozer) C++11
25 / 100
2000 ms 88356 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
const int N=2048;
const int M=2*N;
ll l[M],r[M],sum[M],ans[M];
int A[N];
void pull(int c)
{
	ans[c]=max(max(ans[c<<1],ans[c<<1|1]),r[c<<1]+l[c<<1|1]);
	l[c]=max(l[c<<1],sum[c<<1]+l[c<<1|1]);
	r[c]=max(r[c<<1|1],sum[c<<1|1]+r[c<<1]);
	sum[c]=sum[c<<1]+sum[c<<1|1];
}
void Build()
{
	for(int i=N;i<M;i++) sum[i]=A[i-N],l[i]=r[i]=ans[i]=max(0,A[i-N]);
	for(int i=N-1;i;i--) pull(i);
	/*if(ss==se){ sum[c]=A[ss];l[c]=r[c]=ans[c]=max(0,A[ss]);return;}
	int mid=ss+se>>1;
	Build(c<<1,ss,mid);
	Build(c<<1|1,mid+1,se);
	pull(c);*/
}
void Set(int qi, int x)
{
	qi+=N;sum[qi]=x;l[qi]=r[qi]=ans[qi]=max(x,0);
	for(qi>>=1;qi;qi>>=1) pull(qi);
}
/*void Set(int c, int ss, int se, int qi, int x)
{
	if(ss==se){ sum[c]=x;l[c]=r[c]=ans[c]=max(0,x);return;}
	int mid=ss+se>>1;
	if(qi<=mid) Set(c<<1,ss,mid,qi,x);
	else Set(c<<1|1,mid+1,se,qi,x);
	pull(c);
}*/
struct pt{ ll x,y;pt(){}pt(ll a, ll b):x(a),y(b){}};
bool operator < (pt a, pt b){ return mp(a.y,a.x)<mp(b.y,b.x);}
pt operator - (pt a, pt b){ return pt(a.x-b.x,a.y-b.y);}
ll cross(pt a, pt b){ return a.x*b.y-a.y*b.x;}
ll dot(pt a, pt b){ return a.x*b.x+a.y*b.y;}
ll sq(pt a){ return dot(a,a);}
int part(pt a){ return a<pt(0,0);}
#define ldb double
const ldb PI=acos(-1);
ldb angle(pt a)
{
	ldb ang=atan2(a.y,a.x);
	if(ang<0) ang+=2*PI;
	return ang;
}
bool comp(pt a, pt b){ return mt(part(a),(ll)0)<mt(part(b),cross(a,b));}
bool eq(pt a, pt b){ return comp(a,b)==comp(b,a);}
pt P[N];
int w[N],id[N],pos[N];
ll sol;
void SW(int x, int y)
{
	swap(pos[x],pos[y]);
	swap(A[pos[x]],A[pos[y]]);
	Set(pos[x],A[pos[x]]);
	Set(pos[y],A[pos[y]]);
	//sol=max(sol,ans[1]);
}
int main()
{
    int n;
    scanf("%i",&n);
    for(int i=1;i<=n;i++) scanf("%lld %lld %i",&P[i].x,&P[i].y,&w[i]),id[i]=i;
    sort(id+1,id+1+n,[&](int i, int j){ return P[i]<P[j];});
	for(int i=1;i<=n;i++) A[i]=w[id[i]],pos[id[i]]=i;
	Build();
	sol=ans[1];
	vector<pt> events;
	vector<int> id,X,Y;
	vector<ldb> ang;
	for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++)
	{
		pt d=P[i]-P[j];
		if(part(d)==1) d=pt(0,0)-d;
		id.pb(events.size()),events.pb(d),ang.pb(angle(d));
		X.pb(i);Y.pb(j);
	}
	//sort(events.begin(),events.end(),[&](pair<pt,pair<int,int>> a, pair<pt,pair<int,int>> b){ return comp(a.first,b.first);});
	sort(id.begin(),id.end(),[&](int i, int j){ return comp(events[i],events[j]);});
	for(int i=0,j;i<id.size();i=j)
	{
		vector<int> v;//SW(events[id[j]].second.first,events[id[j]].second.second);
		for(j=i;j<id.size() && eq(events[id[i]],events[id[j]])/*ang[id[i]]==ang[id[j]]*/;j++) v.pb(X[id[j]]),v.pb(Y[id[j]]);
		sort(v.begin(),v.end(),[&](int a, int b){ return pos[a]<pos[b];});
		v.erase(unique(v.begin(),v.end()),v.end());
		for(int k=0,l;k<v.size();k=l)
		{
			for(l=k+1;l<v.size() && pos[v[l-1]]+1==pos[v[l]];l++);
			for(int z=k,t=l-1;z<t;z++,t--) SW(v[z],v[t]);
		}
		/*int x=events[i].second.first;
		int y=events[i].second.second;
		swap(pos[x],pos[y]);
		swap(A[pos[x]],A[pos[y]]);
		Set(pos[x],A[pos[x]]);
		Set(pos[y],A[pos[y]]);
		//printf("SWAP %i %i: %lld\n",x,y,ans[1]);
		sol=max(sol,ans[1]);
		//for(int z=N+1;z<=N+n;z++) printf("%lld ",sum[z]);
		//printf("\n");*/
		sol=max(sol,ans[1]);
	}
	printf("%lld\n",sol);
	return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:91:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0,j;i<id.size();i=j)
                ~^~~~~~~~~~
bulldozer.cpp:94:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=i;j<id.size() && eq(events[id[i]],events[id[j]])/*ang[id[i]]==ang[id[j]]*/;j++) v.pb(X[id[j]]),v.pb(Y[id[j]]);
           ~^~~~~~~~~~
bulldozer.cpp:97:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int k=0,l;k<v.size();k=l)
                 ~^~~~~~~~~
bulldozer.cpp:99:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(l=k+1;l<v.size() && pos[v[l-1]]+1==pos[v[l]];l++);
              ~^~~~~~~~~
bulldozer.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
bulldozer.cpp:74:70: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++) scanf("%lld %lld %i",&P[i].x,&P[i].y,&w[i]),id[i]=i;
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 888 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 3 ms 888 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 3 ms 888 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 3 ms 888 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 760 KB Output is correct
2 Correct 5 ms 760 KB Output is correct
3 Correct 5 ms 760 KB Output is correct
4 Correct 5 ms 764 KB Output is correct
5 Correct 5 ms 760 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 760 KB Output is correct
8 Correct 5 ms 760 KB Output is correct
9 Correct 5 ms 760 KB Output is correct
10 Correct 5 ms 760 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 5 ms 760 KB Output is correct
22 Correct 5 ms 760 KB Output is correct
23 Correct 5 ms 760 KB Output is correct
24 Correct 5 ms 760 KB Output is correct
25 Correct 5 ms 812 KB Output is correct
26 Correct 5 ms 764 KB Output is correct
27 Correct 5 ms 760 KB Output is correct
28 Correct 5 ms 764 KB Output is correct
29 Correct 5 ms 764 KB Output is correct
30 Correct 5 ms 760 KB Output is correct
31 Correct 4 ms 760 KB Output is correct
32 Correct 5 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 760 KB Output is correct
2 Correct 5 ms 760 KB Output is correct
3 Correct 5 ms 760 KB Output is correct
4 Correct 5 ms 764 KB Output is correct
5 Correct 5 ms 760 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 760 KB Output is correct
8 Correct 5 ms 760 KB Output is correct
9 Correct 5 ms 760 KB Output is correct
10 Correct 5 ms 760 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 5 ms 760 KB Output is correct
22 Correct 5 ms 760 KB Output is correct
23 Correct 5 ms 760 KB Output is correct
24 Correct 5 ms 760 KB Output is correct
25 Correct 5 ms 812 KB Output is correct
26 Correct 5 ms 764 KB Output is correct
27 Correct 5 ms 760 KB Output is correct
28 Correct 5 ms 764 KB Output is correct
29 Correct 5 ms 764 KB Output is correct
30 Correct 5 ms 760 KB Output is correct
31 Correct 4 ms 760 KB Output is correct
32 Correct 5 ms 760 KB Output is correct
33 Correct 1970 ms 88356 KB Output is correct
34 Execution timed out 2025 ms 88316 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 760 KB Output is correct
2 Correct 5 ms 760 KB Output is correct
3 Correct 5 ms 760 KB Output is correct
4 Correct 5 ms 764 KB Output is correct
5 Correct 5 ms 760 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 760 KB Output is correct
8 Correct 5 ms 760 KB Output is correct
9 Correct 5 ms 760 KB Output is correct
10 Correct 5 ms 760 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 5 ms 760 KB Output is correct
22 Correct 5 ms 760 KB Output is correct
23 Correct 5 ms 760 KB Output is correct
24 Correct 5 ms 760 KB Output is correct
25 Correct 5 ms 812 KB Output is correct
26 Correct 5 ms 764 KB Output is correct
27 Correct 5 ms 760 KB Output is correct
28 Correct 5 ms 764 KB Output is correct
29 Correct 5 ms 764 KB Output is correct
30 Correct 5 ms 760 KB Output is correct
31 Correct 4 ms 760 KB Output is correct
32 Correct 5 ms 760 KB Output is correct
33 Correct 1970 ms 88356 KB Output is correct
34 Execution timed out 2025 ms 88316 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 888 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 3 ms 888 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 3 ms 888 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 3 ms 888 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 5 ms 760 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
18 Correct 5 ms 760 KB Output is correct
19 Correct 5 ms 764 KB Output is correct
20 Correct 5 ms 760 KB Output is correct
21 Correct 5 ms 760 KB Output is correct
22 Correct 5 ms 760 KB Output is correct
23 Correct 5 ms 760 KB Output is correct
24 Correct 5 ms 760 KB Output is correct
25 Correct 5 ms 760 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 2 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 5 ms 760 KB Output is correct
37 Correct 5 ms 760 KB Output is correct
38 Correct 5 ms 760 KB Output is correct
39 Correct 5 ms 760 KB Output is correct
40 Correct 5 ms 812 KB Output is correct
41 Correct 5 ms 764 KB Output is correct
42 Correct 5 ms 760 KB Output is correct
43 Correct 5 ms 764 KB Output is correct
44 Correct 5 ms 764 KB Output is correct
45 Correct 5 ms 760 KB Output is correct
46 Correct 4 ms 760 KB Output is correct
47 Correct 5 ms 760 KB Output is correct
48 Correct 1970 ms 88356 KB Output is correct
49 Execution timed out 2025 ms 88316 KB Time limit exceeded
50 Halted 0 ms 0 KB -