답안 #1015802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1015802 2024-07-06T20:19:07 Z jamjanek Bulldozer (JOI17_bulldozer) C++14
100 / 100
745 ms 31936 KB
#include<bits/stdc++.h>
using namespace std;
pair<pair<int,int>,int>tab[2010];
int miejsce[2010];
vector<pair<int,int>>vec;
int sign(long long x){
	if(x<0)return -1;
	return x>0;
}
bool notparallel(pair<int,int> a, pair<int,int> b){
	long long Ax=tab[a.first].first.first-tab[a.second].first.first, Ay=tab[a.first].first.second-tab[a.second].first.second, Bx=tab[b.first].first.first-tab[b.second].first.first, By=tab[b.first].first.second-tab[b.second].first.second;
	if(sign(Ax)!=sign(Bx) || sign(Ay)!=sign(By))return 1;
	return Ax*By!=Ay*Bx;
}
bool cmp(pair<int,int>a, pair<int,int>b){
	long long Ax=tab[a.first].first.first-tab[a.second].first.first, Ay=tab[a.first].first.second-tab[a.second].first.second, Bx=tab[b.first].first.first-tab[b.second].first.first, By=tab[b.first].first.second-tab[b.second].first.second;
	if(!notparallel(a,b))return a<b;
	return Ay*Bx>By*Ax;//Ay/Ax>By/Bx;
}
const int base=1<<11;
struct node{long long sum, maxi, lmaxi, rmaxi;};
node tree[2*base];
void ustaw(int x, long long val){
	x+=base;
	tree[x].sum=val;
	tree[x].lmaxi = tree[x].rmaxi = tree[x].maxi=max(0ll,val);
	x/=2;
	while(x>0){
		tree[x].maxi=max({tree[x*2].maxi, tree[x*2+1].maxi, tree[x*2].rmaxi+tree[x*2+1].lmaxi});
		tree[x].sum=tree[x*2].sum+tree[x*2+1].sum;
		tree[x].lmaxi=max(tree[x*2].lmaxi, tree[x*2].sum+tree[x*2+1].lmaxi);
		tree[x].rmaxi=max(tree[x*2+1].rmaxi, tree[x*2+1].sum+tree[x*2].rmaxi);
		x/=2;
	}
}
int main()
{
	int n, i, j;
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d%d%d", &tab[i].first.first, &tab[i].first.second, &tab[i].second);
	}
	sort(tab, tab+n);
	for(i=0;i<n;i++){
		for(j=0;j<n;j++)
			if(tab[j].first.first>tab[i].first.first || (tab[j].first.first==tab[i].first.first && tab[j].first.second>tab[i].first.second)){
			vec.push_back({i,j});
			}
	}
	stable_sort(vec.begin(), vec.end(), cmp);
	for(i=0;i<n;i++){
		ustaw(i, tab[i].second);
		miejsce[i] = i;
	}
	long long res = max(0ll, tree[1].maxi);
	for(i=0;i<(int)vec.size();i++){
		swap(miejsce[vec[i].first], miejsce[vec[i].second]);
		ustaw(miejsce[vec[i].first], tab[vec[i].first].second);
		ustaw(miejsce[vec[i].second], tab[vec[i].second].second);
		if(i!=(int)vec.size()-1 && notparallel(vec[i], vec[i+1]))
			res = max(res, tree[1].maxi);
	}
	printf("%lld\n", res);
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
bulldozer.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%d%d%d", &tab[i].first.first, &tab[i].first.second, &tab[i].second);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 576 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 576 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 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 576 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 576 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 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 728 ms 31868 KB Output is correct
34 Correct 671 ms 31680 KB Output is correct
35 Correct 655 ms 31680 KB Output is correct
36 Correct 651 ms 31664 KB Output is correct
37 Correct 669 ms 31904 KB Output is correct
38 Correct 673 ms 31696 KB Output is correct
39 Correct 670 ms 31840 KB Output is correct
40 Correct 694 ms 31676 KB Output is correct
41 Correct 657 ms 31660 KB Output is correct
42 Correct 686 ms 31712 KB Output is correct
43 Correct 661 ms 31676 KB Output is correct
44 Correct 666 ms 31672 KB Output is correct
45 Correct 649 ms 31664 KB Output is correct
46 Correct 639 ms 31664 KB Output is correct
47 Correct 648 ms 31664 KB Output is correct
48 Correct 644 ms 31676 KB Output is correct
49 Correct 654 ms 31824 KB Output is correct
50 Correct 691 ms 31668 KB Output is correct
51 Correct 637 ms 31668 KB Output is correct
52 Correct 658 ms 31680 KB Output is correct
53 Correct 662 ms 31684 KB Output is correct
54 Correct 684 ms 31748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 576 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 576 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 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 728 ms 31868 KB Output is correct
34 Correct 671 ms 31680 KB Output is correct
35 Correct 655 ms 31680 KB Output is correct
36 Correct 651 ms 31664 KB Output is correct
37 Correct 669 ms 31904 KB Output is correct
38 Correct 673 ms 31696 KB Output is correct
39 Correct 670 ms 31840 KB Output is correct
40 Correct 694 ms 31676 KB Output is correct
41 Correct 657 ms 31660 KB Output is correct
42 Correct 686 ms 31712 KB Output is correct
43 Correct 661 ms 31676 KB Output is correct
44 Correct 666 ms 31672 KB Output is correct
45 Correct 649 ms 31664 KB Output is correct
46 Correct 639 ms 31664 KB Output is correct
47 Correct 648 ms 31664 KB Output is correct
48 Correct 644 ms 31676 KB Output is correct
49 Correct 654 ms 31824 KB Output is correct
50 Correct 691 ms 31668 KB Output is correct
51 Correct 637 ms 31668 KB Output is correct
52 Correct 658 ms 31680 KB Output is correct
53 Correct 662 ms 31684 KB Output is correct
54 Correct 684 ms 31748 KB Output is correct
55 Correct 675 ms 31664 KB Output is correct
56 Correct 677 ms 31668 KB Output is correct
57 Correct 680 ms 31668 KB Output is correct
58 Correct 703 ms 31664 KB Output is correct
59 Correct 687 ms 31688 KB Output is correct
60 Correct 675 ms 31680 KB Output is correct
61 Correct 685 ms 31680 KB Output is correct
62 Correct 671 ms 31852 KB Output is correct
63 Correct 646 ms 31676 KB Output is correct
64 Correct 648 ms 31932 KB Output is correct
65 Correct 642 ms 31664 KB Output is correct
66 Correct 688 ms 31664 KB Output is correct
67 Correct 723 ms 31912 KB Output is correct
68 Correct 693 ms 31668 KB Output is correct
69 Correct 686 ms 31680 KB Output is correct
70 Correct 672 ms 31676 KB Output is correct
71 Correct 664 ms 31668 KB Output is correct
72 Correct 670 ms 31664 KB Output is correct
73 Correct 703 ms 31660 KB Output is correct
74 Correct 684 ms 31880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 576 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 576 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 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 2 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 2 ms 348 KB Output is correct
47 Correct 2 ms 348 KB Output is correct
48 Correct 728 ms 31868 KB Output is correct
49 Correct 671 ms 31680 KB Output is correct
50 Correct 655 ms 31680 KB Output is correct
51 Correct 651 ms 31664 KB Output is correct
52 Correct 669 ms 31904 KB Output is correct
53 Correct 673 ms 31696 KB Output is correct
54 Correct 670 ms 31840 KB Output is correct
55 Correct 694 ms 31676 KB Output is correct
56 Correct 657 ms 31660 KB Output is correct
57 Correct 686 ms 31712 KB Output is correct
58 Correct 661 ms 31676 KB Output is correct
59 Correct 666 ms 31672 KB Output is correct
60 Correct 649 ms 31664 KB Output is correct
61 Correct 639 ms 31664 KB Output is correct
62 Correct 648 ms 31664 KB Output is correct
63 Correct 644 ms 31676 KB Output is correct
64 Correct 654 ms 31824 KB Output is correct
65 Correct 691 ms 31668 KB Output is correct
66 Correct 637 ms 31668 KB Output is correct
67 Correct 658 ms 31680 KB Output is correct
68 Correct 662 ms 31684 KB Output is correct
69 Correct 684 ms 31748 KB Output is correct
70 Correct 675 ms 31664 KB Output is correct
71 Correct 677 ms 31668 KB Output is correct
72 Correct 680 ms 31668 KB Output is correct
73 Correct 703 ms 31664 KB Output is correct
74 Correct 687 ms 31688 KB Output is correct
75 Correct 675 ms 31680 KB Output is correct
76 Correct 685 ms 31680 KB Output is correct
77 Correct 671 ms 31852 KB Output is correct
78 Correct 646 ms 31676 KB Output is correct
79 Correct 648 ms 31932 KB Output is correct
80 Correct 642 ms 31664 KB Output is correct
81 Correct 688 ms 31664 KB Output is correct
82 Correct 723 ms 31912 KB Output is correct
83 Correct 693 ms 31668 KB Output is correct
84 Correct 686 ms 31680 KB Output is correct
85 Correct 672 ms 31676 KB Output is correct
86 Correct 664 ms 31668 KB Output is correct
87 Correct 670 ms 31664 KB Output is correct
88 Correct 703 ms 31660 KB Output is correct
89 Correct 684 ms 31880 KB Output is correct
90 Correct 676 ms 31680 KB Output is correct
91 Correct 672 ms 31740 KB Output is correct
92 Correct 684 ms 31672 KB Output is correct
93 Correct 677 ms 31664 KB Output is correct
94 Correct 647 ms 31668 KB Output is correct
95 Correct 656 ms 31932 KB Output is correct
96 Correct 678 ms 31680 KB Output is correct
97 Correct 657 ms 31680 KB Output is correct
98 Correct 683 ms 31884 KB Output is correct
99 Correct 681 ms 31680 KB Output is correct
100 Correct 498 ms 31776 KB Output is correct
101 Correct 492 ms 31664 KB Output is correct
102 Correct 477 ms 31676 KB Output is correct
103 Correct 516 ms 31900 KB Output is correct
104 Correct 477 ms 31668 KB Output is correct
105 Correct 503 ms 31932 KB Output is correct
106 Correct 518 ms 31644 KB Output is correct
107 Correct 494 ms 31676 KB Output is correct
108 Correct 500 ms 31664 KB Output is correct
109 Correct 559 ms 31676 KB Output is correct
110 Correct 547 ms 31664 KB Output is correct
111 Correct 550 ms 31676 KB Output is correct
112 Correct 557 ms 31920 KB Output is correct
113 Correct 581 ms 31668 KB Output is correct
114 Correct 577 ms 31664 KB Output is correct
115 Correct 566 ms 31668 KB Output is correct
116 Correct 626 ms 31660 KB Output is correct
117 Correct 613 ms 31664 KB Output is correct
118 Correct 560 ms 31668 KB Output is correct
119 Correct 581 ms 31668 KB Output is correct
120 Correct 0 ms 348 KB Output is correct
121 Correct 0 ms 348 KB Output is correct
122 Correct 693 ms 31704 KB Output is correct
123 Correct 646 ms 31652 KB Output is correct
124 Correct 672 ms 31668 KB Output is correct
125 Correct 698 ms 31680 KB Output is correct
126 Correct 720 ms 31936 KB Output is correct
127 Correct 676 ms 31668 KB Output is correct
128 Correct 745 ms 31664 KB Output is correct
129 Correct 641 ms 31668 KB Output is correct
130 Correct 657 ms 31672 KB Output is correct
131 Correct 661 ms 31932 KB Output is correct
132 Correct 688 ms 31680 KB Output is correct
133 Correct 674 ms 31664 KB Output is correct