Submission #1015803

# Submission time Handle Problem Language Result Execution time Memory
1015803 2024-07-06T20:22:09 Z jamjanek Bulldozer (JOI17_bulldozer) C++14
100 / 100
888 ms 17032 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});
			}
	}
	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);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 344 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 556 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 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 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 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 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 3 ms 348 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 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 2 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 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 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 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 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 3 ms 348 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 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 2 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 811 ms 16836 KB Output is correct
34 Correct 801 ms 16832 KB Output is correct
35 Correct 808 ms 16836 KB Output is correct
36 Correct 794 ms 16832 KB Output is correct
37 Correct 810 ms 16836 KB Output is correct
38 Correct 832 ms 16836 KB Output is correct
39 Correct 800 ms 16832 KB Output is correct
40 Correct 762 ms 16836 KB Output is correct
41 Correct 743 ms 16836 KB Output is correct
42 Correct 745 ms 16832 KB Output is correct
43 Correct 733 ms 16836 KB Output is correct
44 Correct 693 ms 16836 KB Output is correct
45 Correct 701 ms 16832 KB Output is correct
46 Correct 751 ms 16836 KB Output is correct
47 Correct 743 ms 16832 KB Output is correct
48 Correct 794 ms 16836 KB Output is correct
49 Correct 755 ms 16836 KB Output is correct
50 Correct 729 ms 16832 KB Output is correct
51 Correct 823 ms 16832 KB Output is correct
52 Correct 751 ms 16836 KB Output is correct
53 Correct 764 ms 16996 KB Output is correct
54 Correct 771 ms 16836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 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 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 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 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 3 ms 348 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 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 2 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 811 ms 16836 KB Output is correct
34 Correct 801 ms 16832 KB Output is correct
35 Correct 808 ms 16836 KB Output is correct
36 Correct 794 ms 16832 KB Output is correct
37 Correct 810 ms 16836 KB Output is correct
38 Correct 832 ms 16836 KB Output is correct
39 Correct 800 ms 16832 KB Output is correct
40 Correct 762 ms 16836 KB Output is correct
41 Correct 743 ms 16836 KB Output is correct
42 Correct 745 ms 16832 KB Output is correct
43 Correct 733 ms 16836 KB Output is correct
44 Correct 693 ms 16836 KB Output is correct
45 Correct 701 ms 16832 KB Output is correct
46 Correct 751 ms 16836 KB Output is correct
47 Correct 743 ms 16832 KB Output is correct
48 Correct 794 ms 16836 KB Output is correct
49 Correct 755 ms 16836 KB Output is correct
50 Correct 729 ms 16832 KB Output is correct
51 Correct 823 ms 16832 KB Output is correct
52 Correct 751 ms 16836 KB Output is correct
53 Correct 764 ms 16996 KB Output is correct
54 Correct 771 ms 16836 KB Output is correct
55 Correct 735 ms 16832 KB Output is correct
56 Correct 750 ms 17032 KB Output is correct
57 Correct 791 ms 16836 KB Output is correct
58 Correct 805 ms 16832 KB Output is correct
59 Correct 724 ms 16836 KB Output is correct
60 Correct 744 ms 16836 KB Output is correct
61 Correct 724 ms 16880 KB Output is correct
62 Correct 743 ms 16836 KB Output is correct
63 Correct 742 ms 16836 KB Output is correct
64 Correct 818 ms 16836 KB Output is correct
65 Correct 797 ms 16836 KB Output is correct
66 Correct 755 ms 16836 KB Output is correct
67 Correct 762 ms 16836 KB Output is correct
68 Correct 870 ms 16832 KB Output is correct
69 Correct 802 ms 16836 KB Output is correct
70 Correct 854 ms 16832 KB Output is correct
71 Correct 793 ms 16836 KB Output is correct
72 Correct 814 ms 16836 KB Output is correct
73 Correct 840 ms 16836 KB Output is correct
74 Correct 800 ms 16832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 344 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 556 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 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 2 ms 344 KB Output is correct
17 Correct 2 ms 348 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 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 344 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 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 3 ms 348 KB Output is correct
38 Correct 2 ms 348 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 2 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 811 ms 16836 KB Output is correct
49 Correct 801 ms 16832 KB Output is correct
50 Correct 808 ms 16836 KB Output is correct
51 Correct 794 ms 16832 KB Output is correct
52 Correct 810 ms 16836 KB Output is correct
53 Correct 832 ms 16836 KB Output is correct
54 Correct 800 ms 16832 KB Output is correct
55 Correct 762 ms 16836 KB Output is correct
56 Correct 743 ms 16836 KB Output is correct
57 Correct 745 ms 16832 KB Output is correct
58 Correct 733 ms 16836 KB Output is correct
59 Correct 693 ms 16836 KB Output is correct
60 Correct 701 ms 16832 KB Output is correct
61 Correct 751 ms 16836 KB Output is correct
62 Correct 743 ms 16832 KB Output is correct
63 Correct 794 ms 16836 KB Output is correct
64 Correct 755 ms 16836 KB Output is correct
65 Correct 729 ms 16832 KB Output is correct
66 Correct 823 ms 16832 KB Output is correct
67 Correct 751 ms 16836 KB Output is correct
68 Correct 764 ms 16996 KB Output is correct
69 Correct 771 ms 16836 KB Output is correct
70 Correct 735 ms 16832 KB Output is correct
71 Correct 750 ms 17032 KB Output is correct
72 Correct 791 ms 16836 KB Output is correct
73 Correct 805 ms 16832 KB Output is correct
74 Correct 724 ms 16836 KB Output is correct
75 Correct 744 ms 16836 KB Output is correct
76 Correct 724 ms 16880 KB Output is correct
77 Correct 743 ms 16836 KB Output is correct
78 Correct 742 ms 16836 KB Output is correct
79 Correct 818 ms 16836 KB Output is correct
80 Correct 797 ms 16836 KB Output is correct
81 Correct 755 ms 16836 KB Output is correct
82 Correct 762 ms 16836 KB Output is correct
83 Correct 870 ms 16832 KB Output is correct
84 Correct 802 ms 16836 KB Output is correct
85 Correct 854 ms 16832 KB Output is correct
86 Correct 793 ms 16836 KB Output is correct
87 Correct 814 ms 16836 KB Output is correct
88 Correct 840 ms 16836 KB Output is correct
89 Correct 800 ms 16832 KB Output is correct
90 Correct 868 ms 16836 KB Output is correct
91 Correct 777 ms 16836 KB Output is correct
92 Correct 795 ms 17008 KB Output is correct
93 Correct 795 ms 16832 KB Output is correct
94 Correct 764 ms 16836 KB Output is correct
95 Correct 823 ms 16836 KB Output is correct
96 Correct 783 ms 16836 KB Output is correct
97 Correct 888 ms 16836 KB Output is correct
98 Correct 791 ms 16832 KB Output is correct
99 Correct 781 ms 16832 KB Output is correct
100 Correct 702 ms 16832 KB Output is correct
101 Correct 707 ms 16832 KB Output is correct
102 Correct 638 ms 16880 KB Output is correct
103 Correct 653 ms 16836 KB Output is correct
104 Correct 645 ms 16940 KB Output is correct
105 Correct 695 ms 16832 KB Output is correct
106 Correct 727 ms 16836 KB Output is correct
107 Correct 686 ms 16836 KB Output is correct
108 Correct 754 ms 16836 KB Output is correct
109 Correct 726 ms 16836 KB Output is correct
110 Correct 707 ms 16888 KB Output is correct
111 Correct 701 ms 16836 KB Output is correct
112 Correct 714 ms 16836 KB Output is correct
113 Correct 731 ms 16836 KB Output is correct
114 Correct 717 ms 16920 KB Output is correct
115 Correct 709 ms 16836 KB Output is correct
116 Correct 706 ms 16832 KB Output is correct
117 Correct 710 ms 16836 KB Output is correct
118 Correct 694 ms 16832 KB Output is correct
119 Correct 725 ms 16832 KB Output is correct
120 Correct 0 ms 344 KB Output is correct
121 Correct 0 ms 348 KB Output is correct
122 Correct 760 ms 16992 KB Output is correct
123 Correct 767 ms 16836 KB Output is correct
124 Correct 754 ms 16836 KB Output is correct
125 Correct 747 ms 16836 KB Output is correct
126 Correct 729 ms 16836 KB Output is correct
127 Correct 768 ms 17028 KB Output is correct
128 Correct 777 ms 16836 KB Output is correct
129 Correct 786 ms 16836 KB Output is correct
130 Correct 740 ms 16836 KB Output is correct
131 Correct 764 ms 16836 KB Output is correct
132 Correct 762 ms 16832 KB Output is correct
133 Correct 715 ms 16832 KB Output is correct