답안 #136172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136172 2019-07-24T21:17:44 Z MetB Bulldozer (JOI17_bulldozer) C++14
80 / 100
756 ms 66400 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;
		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 (); i++)
	{
		if (d[i].b == 0) break;
		ll l = d[i].p1, r = d[i].p2, p_l = p[to[l]], p_r = p[to[r]];

		if (to[l] > to[r]) continue;
 
		t.update (to[r], p_l);
		t.update (to[l], p_r);
	 
		swap (to[l], to[r]);

		/*for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				if (to[i] == 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 (); i++)
                 ~~^~~~~~~~~~~
bulldozer.cpp:113: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);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 2 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 380 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 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 732 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 372 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 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 4 ms 760 KB Output is correct
22 Correct 3 ms 760 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 764 KB Output is correct
27 Correct 4 ms 760 KB Output is correct
28 Correct 3 ms 760 KB Output is correct
29 Correct 3 ms 760 KB Output is correct
30 Correct 3 ms 760 KB Output is correct
31 Correct 3 ms 760 KB Output is correct
32 Correct 3 ms 680 KB Output is correct
# 결과 실행 시간 메모리 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 732 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 372 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 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 4 ms 760 KB Output is correct
22 Correct 3 ms 760 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 764 KB Output is correct
27 Correct 4 ms 760 KB Output is correct
28 Correct 3 ms 760 KB Output is correct
29 Correct 3 ms 760 KB Output is correct
30 Correct 3 ms 760 KB Output is correct
31 Correct 3 ms 760 KB Output is correct
32 Correct 3 ms 680 KB Output is correct
33 Correct 717 ms 66200 KB Output is correct
34 Correct 708 ms 66200 KB Output is correct
35 Correct 705 ms 66196 KB Output is correct
36 Correct 734 ms 66172 KB Output is correct
37 Correct 709 ms 66200 KB Output is correct
38 Correct 725 ms 66204 KB Output is correct
39 Correct 752 ms 66400 KB Output is correct
40 Correct 723 ms 66200 KB Output is correct
41 Correct 747 ms 66200 KB Output is correct
42 Correct 756 ms 66200 KB Output is correct
43 Correct 705 ms 66200 KB Output is correct
44 Correct 701 ms 66204 KB Output is correct
45 Correct 696 ms 66200 KB Output is correct
46 Correct 700 ms 66256 KB Output is correct
47 Correct 698 ms 66200 KB Output is correct
48 Correct 716 ms 66200 KB Output is correct
49 Correct 709 ms 66200 KB Output is correct
50 Correct 706 ms 66200 KB Output is correct
51 Correct 754 ms 66228 KB Output is correct
52 Correct 719 ms 66200 KB Output is correct
53 Correct 702 ms 66200 KB Output is correct
54 Correct 746 ms 66200 KB Output is correct
# 결과 실행 시간 메모리 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 732 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 372 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 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 4 ms 760 KB Output is correct
22 Correct 3 ms 760 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 764 KB Output is correct
27 Correct 4 ms 760 KB Output is correct
28 Correct 3 ms 760 KB Output is correct
29 Correct 3 ms 760 KB Output is correct
30 Correct 3 ms 760 KB Output is correct
31 Correct 3 ms 760 KB Output is correct
32 Correct 3 ms 680 KB Output is correct
33 Correct 717 ms 66200 KB Output is correct
34 Correct 708 ms 66200 KB Output is correct
35 Correct 705 ms 66196 KB Output is correct
36 Correct 734 ms 66172 KB Output is correct
37 Correct 709 ms 66200 KB Output is correct
38 Correct 725 ms 66204 KB Output is correct
39 Correct 752 ms 66400 KB Output is correct
40 Correct 723 ms 66200 KB Output is correct
41 Correct 747 ms 66200 KB Output is correct
42 Correct 756 ms 66200 KB Output is correct
43 Correct 705 ms 66200 KB Output is correct
44 Correct 701 ms 66204 KB Output is correct
45 Correct 696 ms 66200 KB Output is correct
46 Correct 700 ms 66256 KB Output is correct
47 Correct 698 ms 66200 KB Output is correct
48 Correct 716 ms 66200 KB Output is correct
49 Correct 709 ms 66200 KB Output is correct
50 Correct 706 ms 66200 KB Output is correct
51 Correct 754 ms 66228 KB Output is correct
52 Correct 719 ms 66200 KB Output is correct
53 Correct 702 ms 66200 KB Output is correct
54 Correct 746 ms 66200 KB Output is correct
55 Correct 713 ms 66272 KB Output is correct
56 Correct 722 ms 66196 KB Output is correct
57 Correct 745 ms 66200 KB Output is correct
58 Correct 716 ms 66200 KB Output is correct
59 Correct 724 ms 66200 KB Output is correct
60 Correct 706 ms 66228 KB Output is correct
61 Correct 714 ms 66328 KB Output is correct
62 Correct 730 ms 66172 KB Output is correct
63 Correct 724 ms 66172 KB Output is correct
64 Correct 708 ms 66200 KB Output is correct
65 Correct 738 ms 66200 KB Output is correct
66 Correct 710 ms 66188 KB Output is correct
67 Correct 714 ms 66200 KB Output is correct
68 Correct 742 ms 66284 KB Output is correct
69 Correct 752 ms 66200 KB Output is correct
70 Correct 712 ms 66200 KB Output is correct
71 Correct 727 ms 66172 KB Output is correct
72 Correct 727 ms 66200 KB Output is correct
73 Correct 748 ms 66200 KB Output is correct
74 Correct 753 ms 66200 KB Output is correct
# 결과 실행 시간 메모리 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 2 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 380 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 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 3 ms 760 KB Output is correct
20 Correct 3 ms 732 KB Output is correct
21 Correct 3 ms 760 KB Output is correct
22 Correct 3 ms 760 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 2 ms 372 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 376 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 380 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 4 ms 760 KB Output is correct
37 Correct 3 ms 760 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 764 KB Output is correct
42 Correct 4 ms 760 KB Output is correct
43 Correct 3 ms 760 KB Output is correct
44 Correct 3 ms 760 KB Output is correct
45 Correct 3 ms 760 KB Output is correct
46 Correct 3 ms 760 KB Output is correct
47 Correct 3 ms 680 KB Output is correct
48 Correct 717 ms 66200 KB Output is correct
49 Correct 708 ms 66200 KB Output is correct
50 Correct 705 ms 66196 KB Output is correct
51 Correct 734 ms 66172 KB Output is correct
52 Correct 709 ms 66200 KB Output is correct
53 Correct 725 ms 66204 KB Output is correct
54 Correct 752 ms 66400 KB Output is correct
55 Correct 723 ms 66200 KB Output is correct
56 Correct 747 ms 66200 KB Output is correct
57 Correct 756 ms 66200 KB Output is correct
58 Correct 705 ms 66200 KB Output is correct
59 Correct 701 ms 66204 KB Output is correct
60 Correct 696 ms 66200 KB Output is correct
61 Correct 700 ms 66256 KB Output is correct
62 Correct 698 ms 66200 KB Output is correct
63 Correct 716 ms 66200 KB Output is correct
64 Correct 709 ms 66200 KB Output is correct
65 Correct 706 ms 66200 KB Output is correct
66 Correct 754 ms 66228 KB Output is correct
67 Correct 719 ms 66200 KB Output is correct
68 Correct 702 ms 66200 KB Output is correct
69 Correct 746 ms 66200 KB Output is correct
70 Correct 713 ms 66272 KB Output is correct
71 Correct 722 ms 66196 KB Output is correct
72 Correct 745 ms 66200 KB Output is correct
73 Correct 716 ms 66200 KB Output is correct
74 Correct 724 ms 66200 KB Output is correct
75 Correct 706 ms 66228 KB Output is correct
76 Correct 714 ms 66328 KB Output is correct
77 Correct 730 ms 66172 KB Output is correct
78 Correct 724 ms 66172 KB Output is correct
79 Correct 708 ms 66200 KB Output is correct
80 Correct 738 ms 66200 KB Output is correct
81 Correct 710 ms 66188 KB Output is correct
82 Correct 714 ms 66200 KB Output is correct
83 Correct 742 ms 66284 KB Output is correct
84 Correct 752 ms 66200 KB Output is correct
85 Correct 712 ms 66200 KB Output is correct
86 Correct 727 ms 66172 KB Output is correct
87 Correct 727 ms 66200 KB Output is correct
88 Correct 748 ms 66200 KB Output is correct
89 Correct 753 ms 66200 KB Output is correct
90 Correct 722 ms 66200 KB Output is correct
91 Correct 714 ms 66324 KB Output is correct
92 Correct 731 ms 66200 KB Output is correct
93 Correct 718 ms 66200 KB Output is correct
94 Correct 713 ms 66200 KB Output is correct
95 Correct 708 ms 66200 KB Output is correct
96 Correct 709 ms 66380 KB Output is correct
97 Correct 735 ms 66200 KB Output is correct
98 Correct 735 ms 66200 KB Output is correct
99 Correct 724 ms 66328 KB Output is correct
100 Incorrect 460 ms 66200 KB Output isn't correct
101 Halted 0 ms 0 KB -