답안 #151136

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151136 2019-09-01T20:41:27 Z TadijaSebez Bulldozer (JOI17_bulldozer) C++11
100 / 100
705 ms 47656 KB
#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);
}
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);
}
struct pt{ ll x,y,w;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]);
	Set(pos[x],P[x].w);
	Set(pos[y],P[y].w);
}
ll cross(ll ax, ll ay, ll bx, ll by){ return ax*by-ay*bx;}
struct Event
{
	ll x,y;
	int i,j;
	Event(){}
	Event(ll a, ll b, int c, int d):x(a),y(b),i(c),j(d){}
	bool operator < (Event b){ return cross(x,y,b.x,b.y)==0?mp(i,j)<mp(b.i,b.j):cross(x,y,b.x,b.y)>0;}
} evs[N*N];
int main()
{
    int n;
    scanf("%i",&n);
    for(int i=1;i<=n;i++) scanf("%lld %lld %lld",&P[i].x,&P[i].y,&P[i].w),id[i]=i;
    sort(P+1,P+1+n);
	for(int i=1;i<=n;i++) A[i]=P[i].w,pos[i]=i;
	Build();
	sol=ans[1];
	int tot=0;
	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;
		evs[++tot]=Event(d.x,d.y,i,j);
	}
	sort(evs+1,evs+1+tot);
	for(int i=1,j;i<=tot;i=j)
	{
		for(j=i;j<=tot && cross(evs[i].x,evs[i].y,evs[j].x,evs[j].y)==0;j++) SW(evs[j].i,evs[j].j);
		sol=max(sol,ans[1]);
	}
	printf("%lld\n",sol);
	return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
bulldozer.cpp:67:74: 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 %lld",&P[i].x,&P[i].y,&P[i].w),id[i]=i;
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 3 ms 632 KB Output is correct
9 Correct 3 ms 632 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 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 4 ms 632 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 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 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 632 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 3 ms 632 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 ms 632 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 3 ms 632 KB Output is correct
28 Correct 3 ms 632 KB Output is correct
29 Correct 3 ms 632 KB Output is correct
30 Correct 3 ms 632 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 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 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 632 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 3 ms 632 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 ms 632 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 3 ms 632 KB Output is correct
28 Correct 3 ms 632 KB Output is correct
29 Correct 3 ms 632 KB Output is correct
30 Correct 3 ms 632 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 650 ms 47516 KB Output is correct
34 Correct 651 ms 47480 KB Output is correct
35 Correct 663 ms 47512 KB Output is correct
36 Correct 697 ms 47612 KB Output is correct
37 Correct 652 ms 47516 KB Output is correct
38 Correct 648 ms 47480 KB Output is correct
39 Correct 661 ms 47580 KB Output is correct
40 Correct 660 ms 47512 KB Output is correct
41 Correct 648 ms 47520 KB Output is correct
42 Correct 662 ms 47608 KB Output is correct
43 Correct 646 ms 47608 KB Output is correct
44 Correct 644 ms 47480 KB Output is correct
45 Correct 701 ms 47608 KB Output is correct
46 Correct 641 ms 47608 KB Output is correct
47 Correct 655 ms 47608 KB Output is correct
48 Correct 660 ms 47492 KB Output is correct
49 Correct 647 ms 47608 KB Output is correct
50 Correct 647 ms 47608 KB Output is correct
51 Correct 650 ms 47516 KB Output is correct
52 Correct 649 ms 47608 KB Output is correct
53 Correct 657 ms 47608 KB Output is correct
54 Correct 662 ms 47480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 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 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 632 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 3 ms 632 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 ms 632 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 3 ms 632 KB Output is correct
28 Correct 3 ms 632 KB Output is correct
29 Correct 3 ms 632 KB Output is correct
30 Correct 3 ms 632 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 650 ms 47516 KB Output is correct
34 Correct 651 ms 47480 KB Output is correct
35 Correct 663 ms 47512 KB Output is correct
36 Correct 697 ms 47612 KB Output is correct
37 Correct 652 ms 47516 KB Output is correct
38 Correct 648 ms 47480 KB Output is correct
39 Correct 661 ms 47580 KB Output is correct
40 Correct 660 ms 47512 KB Output is correct
41 Correct 648 ms 47520 KB Output is correct
42 Correct 662 ms 47608 KB Output is correct
43 Correct 646 ms 47608 KB Output is correct
44 Correct 644 ms 47480 KB Output is correct
45 Correct 701 ms 47608 KB Output is correct
46 Correct 641 ms 47608 KB Output is correct
47 Correct 655 ms 47608 KB Output is correct
48 Correct 660 ms 47492 KB Output is correct
49 Correct 647 ms 47608 KB Output is correct
50 Correct 647 ms 47608 KB Output is correct
51 Correct 650 ms 47516 KB Output is correct
52 Correct 649 ms 47608 KB Output is correct
53 Correct 657 ms 47608 KB Output is correct
54 Correct 662 ms 47480 KB Output is correct
55 Correct 656 ms 47516 KB Output is correct
56 Correct 652 ms 47608 KB Output is correct
57 Correct 654 ms 47552 KB Output is correct
58 Correct 680 ms 47524 KB Output is correct
59 Correct 688 ms 47500 KB Output is correct
60 Correct 695 ms 47516 KB Output is correct
61 Correct 681 ms 47520 KB Output is correct
62 Correct 674 ms 47608 KB Output is correct
63 Correct 682 ms 47520 KB Output is correct
64 Correct 665 ms 47576 KB Output is correct
65 Correct 657 ms 47516 KB Output is correct
66 Correct 676 ms 47516 KB Output is correct
67 Correct 705 ms 47512 KB Output is correct
68 Correct 653 ms 47608 KB Output is correct
69 Correct 646 ms 47520 KB Output is correct
70 Correct 648 ms 47608 KB Output is correct
71 Correct 656 ms 47516 KB Output is correct
72 Correct 654 ms 47604 KB Output is correct
73 Correct 646 ms 47608 KB Output is correct
74 Correct 645 ms 47608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 3 ms 632 KB Output is correct
9 Correct 3 ms 632 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 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 4 ms 632 KB Output is correct
17 Correct 4 ms 632 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 4 ms 632 KB Output is correct
20 Correct 4 ms 632 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 3 ms 504 KB Output is correct
23 Correct 4 ms 632 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
25 Correct 4 ms 632 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 2 ms 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 2 ms 632 KB Output is correct
36 Correct 4 ms 632 KB Output is correct
37 Correct 3 ms 632 KB Output is correct
38 Correct 3 ms 632 KB Output is correct
39 Correct 3 ms 632 KB Output is correct
40 Correct 3 ms 632 KB Output is correct
41 Correct 3 ms 632 KB Output is correct
42 Correct 3 ms 632 KB Output is correct
43 Correct 3 ms 632 KB Output is correct
44 Correct 3 ms 632 KB Output is correct
45 Correct 3 ms 632 KB Output is correct
46 Correct 3 ms 632 KB Output is correct
47 Correct 3 ms 632 KB Output is correct
48 Correct 650 ms 47516 KB Output is correct
49 Correct 651 ms 47480 KB Output is correct
50 Correct 663 ms 47512 KB Output is correct
51 Correct 697 ms 47612 KB Output is correct
52 Correct 652 ms 47516 KB Output is correct
53 Correct 648 ms 47480 KB Output is correct
54 Correct 661 ms 47580 KB Output is correct
55 Correct 660 ms 47512 KB Output is correct
56 Correct 648 ms 47520 KB Output is correct
57 Correct 662 ms 47608 KB Output is correct
58 Correct 646 ms 47608 KB Output is correct
59 Correct 644 ms 47480 KB Output is correct
60 Correct 701 ms 47608 KB Output is correct
61 Correct 641 ms 47608 KB Output is correct
62 Correct 655 ms 47608 KB Output is correct
63 Correct 660 ms 47492 KB Output is correct
64 Correct 647 ms 47608 KB Output is correct
65 Correct 647 ms 47608 KB Output is correct
66 Correct 650 ms 47516 KB Output is correct
67 Correct 649 ms 47608 KB Output is correct
68 Correct 657 ms 47608 KB Output is correct
69 Correct 662 ms 47480 KB Output is correct
70 Correct 656 ms 47516 KB Output is correct
71 Correct 652 ms 47608 KB Output is correct
72 Correct 654 ms 47552 KB Output is correct
73 Correct 680 ms 47524 KB Output is correct
74 Correct 688 ms 47500 KB Output is correct
75 Correct 695 ms 47516 KB Output is correct
76 Correct 681 ms 47520 KB Output is correct
77 Correct 674 ms 47608 KB Output is correct
78 Correct 682 ms 47520 KB Output is correct
79 Correct 665 ms 47576 KB Output is correct
80 Correct 657 ms 47516 KB Output is correct
81 Correct 676 ms 47516 KB Output is correct
82 Correct 705 ms 47512 KB Output is correct
83 Correct 653 ms 47608 KB Output is correct
84 Correct 646 ms 47520 KB Output is correct
85 Correct 648 ms 47608 KB Output is correct
86 Correct 656 ms 47516 KB Output is correct
87 Correct 654 ms 47604 KB Output is correct
88 Correct 646 ms 47608 KB Output is correct
89 Correct 645 ms 47608 KB Output is correct
90 Correct 649 ms 47576 KB Output is correct
91 Correct 645 ms 47576 KB Output is correct
92 Correct 651 ms 47608 KB Output is correct
93 Correct 655 ms 47480 KB Output is correct
94 Correct 661 ms 47576 KB Output is correct
95 Correct 686 ms 47620 KB Output is correct
96 Correct 656 ms 47612 KB Output is correct
97 Correct 677 ms 47584 KB Output is correct
98 Correct 665 ms 47580 KB Output is correct
99 Correct 659 ms 47608 KB Output is correct
100 Correct 597 ms 47608 KB Output is correct
101 Correct 638 ms 47564 KB Output is correct
102 Correct 614 ms 47564 KB Output is correct
103 Correct 586 ms 47560 KB Output is correct
104 Correct 603 ms 47564 KB Output is correct
105 Correct 628 ms 47608 KB Output is correct
106 Correct 643 ms 47608 KB Output is correct
107 Correct 619 ms 47608 KB Output is correct
108 Correct 624 ms 47568 KB Output is correct
109 Correct 636 ms 47564 KB Output is correct
110 Correct 633 ms 47560 KB Output is correct
111 Correct 629 ms 47552 KB Output is correct
112 Correct 644 ms 47560 KB Output is correct
113 Correct 637 ms 47556 KB Output is correct
114 Correct 636 ms 47656 KB Output is correct
115 Correct 642 ms 47608 KB Output is correct
116 Correct 633 ms 47556 KB Output is correct
117 Correct 646 ms 47556 KB Output is correct
118 Correct 632 ms 47608 KB Output is correct
119 Correct 631 ms 47556 KB Output is correct
120 Correct 3 ms 504 KB Output is correct
121 Correct 3 ms 504 KB Output is correct
122 Correct 643 ms 47608 KB Output is correct
123 Correct 649 ms 47580 KB Output is correct
124 Correct 676 ms 47576 KB Output is correct
125 Correct 661 ms 47580 KB Output is correct
126 Correct 642 ms 47576 KB Output is correct
127 Correct 665 ms 47584 KB Output is correct
128 Correct 662 ms 47608 KB Output is correct
129 Correct 660 ms 47580 KB Output is correct
130 Correct 658 ms 47584 KB Output is correct
131 Correct 655 ms 47608 KB Output is correct
132 Correct 657 ms 47480 KB Output is correct
133 Correct 650 ms 47576 KB Output is correct