Submission #136352

# Submission time Handle Problem Language Result Execution time Memory
136352 2019-07-25T07:33:27 Z MetB Bulldozer (JOI17_bulldozer) C++14
100 / 100
781 ms 66472 KB
#include <algorithm>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <bitset>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
 
typedef long long ll;
typedef long double ld;
 
const ll MOD = 1e9 + 7, INF = 1e18 + 1;
 
using namespace std;

ll p[1000000], to[10000], n;

struct SegTree
{
	ll t[80000][4], start;
 
	ll operator[] (const int& i)
	{
		return t[i][0];
	}
 
	void build (ll n)
	{
		start = 1;
 
		while (start < n) start <<= 1;
 
		for (ll i = 2 * start - 1; i; i--)
			merge (i);
	}
 
	void merge (ll node)
	{
		if (node >= start) 
		{
			t[node][3] = p[node - start];
			t[node][2] = max (0LL, p[node - start]);
			t[node][1] = max (0LL, p[node - start]);
			t[node][0] = max (0LL, p[node - start]);
		}
		else
		{
			t[node][3] = t[2 * node][3] + t[2 * node + 1][3];
			t[node][2] = max (t[2 * node][3] + t[2 * node + 1][2], t[2 * node][2]);
			t[node][1] = max (t[2 * node][1] + t[2 * node + 1][3], t[2 * node + 1][1]);
			t[node][0] = max (max (t[2 * node][0], t[2 * node + 1][0]), t[2 * node][1] + t[2 * node + 1][2]);
		}
	}
 
	void update (ll x, ll d)
	{
		p[x] = d;
		x += start;
 
		while (x)
		{
			merge (x);
			x /= 2;
		}
	}
} t;

struct point
{
	ll x, y, c;

	bool operator < (const point& b) const
	{
		return (y == b.y ? x < b.x : y > b.y);
	}

} a[2000];

struct fraction
{
	ll a, b;

	ll p1, p2;

	bool operator < (const fraction& d) const
	{
		if (!d.b && !b) return a < d.a;
		if (!d.b) return true;
		if (!b) return false;
		if ((a * d.b) == (b * d.a)) return make_pair (p1, p2) < make_pair (d.p1, d.p2);
		return (a * d.b) < (b * d.a);
	}

	bool operator == (const fraction& d) const
	{
		if (!b && !d.b) return true;
		if (!b || !d.b) return false;
		return (a * d.b) == (b * d.a);
	}
};

vector <fraction> d;

int main ()
{
	cin >> n;

	for (ll i = 0; i < n; i++)
		scanf ("%lld%lld%lld", &a[i].x, &a[i].y, &a[i].c);

	sort (a, a + n);

	for (ll i = 0; i < n; i++)
	{
		p[i] = a[i].c;
		to[i] = i;
	}

	for (ll i = 0; i < n; i++)
		for (ll j = i + 1; j < n; j++)
		{
			ll A = a[i].y - a[j].y;
			ll B = a[i].x - a[j].x;

			d.push_back ({-B, A, i, j});
		}

	sort (d.begin(), d.end());

	t.build (n);

	ll ans = t[1];
	
	for (ll i = 0; i < d.size ();)
	{
		if (d[i].b == 0) break;

		int k = 0;

		while (i + k < d.size () && d[i + k] == d[i])
		{
			ll l = d[i + k].p1, r = d[i + k].p2, p_l = p[to[l]], p_r = p[to[r]];

			t.update (to[r], p_l);
			t.update (to[l], p_r);
		 
			swap (to[l], to[r]);
			k++;
		}

		i += k;

		/*cout << k << ' ';

		for (int c = 0; c < n; c++)
			for (int j = 0; j < n; j++)
				if (to[c] == j)
					cout << "(" << a[j].x << ", " << a[j].y << ") ";
		cout << endl;*/

		ans = max (ans, t[1]);
	}

	cout << ans;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:139:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (ll i = 0; i < d.size ();)
                 ~~^~~~~~~~~~~
bulldozer.cpp:145:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (i + k < d.size () && d[i + k] == d[i])
          ~~~~~~^~~~~~~~~~~
bulldozer.cpp:114:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%lld%lld%lld", &a[i].x, &a[i].y, &a[i].c);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 760 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 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 4 ms 888 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 9 ms 760 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 4 ms 760 KB Output is correct
9 Correct 3 ms 744 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 292 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 760 KB Output is correct
22 Correct 3 ms 748 KB Output is correct
23 Correct 3 ms 760 KB Output is correct
24 Correct 3 ms 760 KB Output is correct
25 Correct 3 ms 760 KB Output is correct
26 Correct 3 ms 760 KB Output is correct
27 Correct 3 ms 760 KB Output is correct
28 Correct 5 ms 760 KB Output is correct
29 Correct 3 ms 760 KB Output is correct
30 Correct 3 ms 732 KB Output is correct
31 Correct 3 ms 732 KB Output is correct
32 Correct 4 ms 752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 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 4 ms 888 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 9 ms 760 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 4 ms 760 KB Output is correct
9 Correct 3 ms 744 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 292 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 760 KB Output is correct
22 Correct 3 ms 748 KB Output is correct
23 Correct 3 ms 760 KB Output is correct
24 Correct 3 ms 760 KB Output is correct
25 Correct 3 ms 760 KB Output is correct
26 Correct 3 ms 760 KB Output is correct
27 Correct 3 ms 760 KB Output is correct
28 Correct 5 ms 760 KB Output is correct
29 Correct 3 ms 760 KB Output is correct
30 Correct 3 ms 732 KB Output is correct
31 Correct 3 ms 732 KB Output is correct
32 Correct 4 ms 752 KB Output is correct
33 Correct 747 ms 66232 KB Output is correct
34 Correct 770 ms 66272 KB Output is correct
35 Correct 733 ms 66336 KB Output is correct
36 Correct 769 ms 66456 KB Output is correct
37 Correct 772 ms 66328 KB Output is correct
38 Correct 763 ms 66328 KB Output is correct
39 Correct 740 ms 66328 KB Output is correct
40 Correct 746 ms 66332 KB Output is correct
41 Correct 730 ms 66276 KB Output is correct
42 Correct 759 ms 66328 KB Output is correct
43 Correct 724 ms 66348 KB Output is correct
44 Correct 717 ms 66328 KB Output is correct
45 Correct 731 ms 66456 KB Output is correct
46 Correct 724 ms 66328 KB Output is correct
47 Correct 727 ms 66328 KB Output is correct
48 Correct 734 ms 66328 KB Output is correct
49 Correct 730 ms 66328 KB Output is correct
50 Correct 729 ms 66468 KB Output is correct
51 Correct 727 ms 66328 KB Output is correct
52 Correct 725 ms 66300 KB Output is correct
53 Correct 720 ms 66328 KB Output is correct
54 Correct 735 ms 66332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 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 4 ms 888 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 9 ms 760 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 4 ms 760 KB Output is correct
9 Correct 3 ms 744 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 292 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 760 KB Output is correct
22 Correct 3 ms 748 KB Output is correct
23 Correct 3 ms 760 KB Output is correct
24 Correct 3 ms 760 KB Output is correct
25 Correct 3 ms 760 KB Output is correct
26 Correct 3 ms 760 KB Output is correct
27 Correct 3 ms 760 KB Output is correct
28 Correct 5 ms 760 KB Output is correct
29 Correct 3 ms 760 KB Output is correct
30 Correct 3 ms 732 KB Output is correct
31 Correct 3 ms 732 KB Output is correct
32 Correct 4 ms 752 KB Output is correct
33 Correct 747 ms 66232 KB Output is correct
34 Correct 770 ms 66272 KB Output is correct
35 Correct 733 ms 66336 KB Output is correct
36 Correct 769 ms 66456 KB Output is correct
37 Correct 772 ms 66328 KB Output is correct
38 Correct 763 ms 66328 KB Output is correct
39 Correct 740 ms 66328 KB Output is correct
40 Correct 746 ms 66332 KB Output is correct
41 Correct 730 ms 66276 KB Output is correct
42 Correct 759 ms 66328 KB Output is correct
43 Correct 724 ms 66348 KB Output is correct
44 Correct 717 ms 66328 KB Output is correct
45 Correct 731 ms 66456 KB Output is correct
46 Correct 724 ms 66328 KB Output is correct
47 Correct 727 ms 66328 KB Output is correct
48 Correct 734 ms 66328 KB Output is correct
49 Correct 730 ms 66328 KB Output is correct
50 Correct 729 ms 66468 KB Output is correct
51 Correct 727 ms 66328 KB Output is correct
52 Correct 725 ms 66300 KB Output is correct
53 Correct 720 ms 66328 KB Output is correct
54 Correct 735 ms 66332 KB Output is correct
55 Correct 728 ms 66240 KB Output is correct
56 Correct 753 ms 66328 KB Output is correct
57 Correct 730 ms 66336 KB Output is correct
58 Correct 737 ms 66300 KB Output is correct
59 Correct 749 ms 66328 KB Output is correct
60 Correct 729 ms 66328 KB Output is correct
61 Correct 738 ms 66200 KB Output is correct
62 Correct 746 ms 66384 KB Output is correct
63 Correct 742 ms 66460 KB Output is correct
64 Correct 729 ms 66328 KB Output is correct
65 Correct 727 ms 66300 KB Output is correct
66 Correct 734 ms 66328 KB Output is correct
67 Correct 742 ms 66328 KB Output is correct
68 Correct 747 ms 66200 KB Output is correct
69 Correct 739 ms 66332 KB Output is correct
70 Correct 738 ms 66328 KB Output is correct
71 Correct 751 ms 66328 KB Output is correct
72 Correct 755 ms 66344 KB Output is correct
73 Correct 739 ms 66200 KB Output is correct
74 Correct 738 ms 66268 KB Output is correct
# Verdict Execution time Memory 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 760 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 4 ms 760 KB Output is correct
17 Correct 3 ms 760 KB Output is correct
18 Correct 3 ms 760 KB Output is correct
19 Correct 4 ms 888 KB Output is correct
20 Correct 3 ms 760 KB Output is correct
21 Correct 9 ms 760 KB Output is correct
22 Correct 3 ms 760 KB Output is correct
23 Correct 4 ms 760 KB Output is correct
24 Correct 3 ms 744 KB Output is correct
25 Correct 3 ms 760 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 292 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 3 ms 760 KB Output is correct
37 Correct 3 ms 748 KB Output is correct
38 Correct 3 ms 760 KB Output is correct
39 Correct 3 ms 760 KB Output is correct
40 Correct 3 ms 760 KB Output is correct
41 Correct 3 ms 760 KB Output is correct
42 Correct 3 ms 760 KB Output is correct
43 Correct 5 ms 760 KB Output is correct
44 Correct 3 ms 760 KB Output is correct
45 Correct 3 ms 732 KB Output is correct
46 Correct 3 ms 732 KB Output is correct
47 Correct 4 ms 752 KB Output is correct
48 Correct 747 ms 66232 KB Output is correct
49 Correct 770 ms 66272 KB Output is correct
50 Correct 733 ms 66336 KB Output is correct
51 Correct 769 ms 66456 KB Output is correct
52 Correct 772 ms 66328 KB Output is correct
53 Correct 763 ms 66328 KB Output is correct
54 Correct 740 ms 66328 KB Output is correct
55 Correct 746 ms 66332 KB Output is correct
56 Correct 730 ms 66276 KB Output is correct
57 Correct 759 ms 66328 KB Output is correct
58 Correct 724 ms 66348 KB Output is correct
59 Correct 717 ms 66328 KB Output is correct
60 Correct 731 ms 66456 KB Output is correct
61 Correct 724 ms 66328 KB Output is correct
62 Correct 727 ms 66328 KB Output is correct
63 Correct 734 ms 66328 KB Output is correct
64 Correct 730 ms 66328 KB Output is correct
65 Correct 729 ms 66468 KB Output is correct
66 Correct 727 ms 66328 KB Output is correct
67 Correct 725 ms 66300 KB Output is correct
68 Correct 720 ms 66328 KB Output is correct
69 Correct 735 ms 66332 KB Output is correct
70 Correct 728 ms 66240 KB Output is correct
71 Correct 753 ms 66328 KB Output is correct
72 Correct 730 ms 66336 KB Output is correct
73 Correct 737 ms 66300 KB Output is correct
74 Correct 749 ms 66328 KB Output is correct
75 Correct 729 ms 66328 KB Output is correct
76 Correct 738 ms 66200 KB Output is correct
77 Correct 746 ms 66384 KB Output is correct
78 Correct 742 ms 66460 KB Output is correct
79 Correct 729 ms 66328 KB Output is correct
80 Correct 727 ms 66300 KB Output is correct
81 Correct 734 ms 66328 KB Output is correct
82 Correct 742 ms 66328 KB Output is correct
83 Correct 747 ms 66200 KB Output is correct
84 Correct 739 ms 66332 KB Output is correct
85 Correct 738 ms 66328 KB Output is correct
86 Correct 751 ms 66328 KB Output is correct
87 Correct 755 ms 66344 KB Output is correct
88 Correct 739 ms 66200 KB Output is correct
89 Correct 738 ms 66268 KB Output is correct
90 Correct 781 ms 66252 KB Output is correct
91 Correct 738 ms 66332 KB Output is correct
92 Correct 757 ms 66200 KB Output is correct
93 Correct 757 ms 66328 KB Output is correct
94 Correct 741 ms 66316 KB Output is correct
95 Correct 728 ms 66328 KB Output is correct
96 Correct 739 ms 66200 KB Output is correct
97 Correct 752 ms 66276 KB Output is correct
98 Correct 729 ms 66196 KB Output is correct
99 Correct 736 ms 66328 KB Output is correct
100 Correct 714 ms 66328 KB Output is correct
101 Correct 748 ms 66300 KB Output is correct
102 Correct 678 ms 66364 KB Output is correct
103 Correct 688 ms 66336 KB Output is correct
104 Correct 703 ms 66388 KB Output is correct
105 Correct 718 ms 66204 KB Output is correct
106 Correct 710 ms 66200 KB Output is correct
107 Correct 734 ms 66328 KB Output is correct
108 Correct 707 ms 66364 KB Output is correct
109 Correct 701 ms 66328 KB Output is correct
110 Correct 713 ms 66200 KB Output is correct
111 Correct 715 ms 66328 KB Output is correct
112 Correct 713 ms 66328 KB Output is correct
113 Correct 718 ms 66456 KB Output is correct
114 Correct 722 ms 66344 KB Output is correct
115 Correct 725 ms 66200 KB Output is correct
116 Correct 716 ms 66328 KB Output is correct
117 Correct 717 ms 66364 KB Output is correct
118 Correct 713 ms 66272 KB Output is correct
119 Correct 714 ms 66384 KB Output is correct
120 Correct 2 ms 376 KB Output is correct
121 Correct 2 ms 376 KB Output is correct
122 Correct 737 ms 66472 KB Output is correct
123 Correct 754 ms 66240 KB Output is correct
124 Correct 757 ms 66376 KB Output is correct
125 Correct 732 ms 66468 KB Output is correct
126 Correct 727 ms 66324 KB Output is correct
127 Correct 733 ms 66336 KB Output is correct
128 Correct 737 ms 66328 KB Output is correct
129 Correct 727 ms 66328 KB Output is correct
130 Correct 755 ms 66328 KB Output is correct
131 Correct 735 ms 66200 KB Output is correct
132 Correct 728 ms 66200 KB Output is correct
133 Correct 728 ms 66200 KB Output is correct