Submission #26654

# Submission time Handle Problem Language Result Execution time Memory
26654 2017-07-04T05:37:46 Z kajebiii Bulldozer (JOI17_bulldozer) C++14
100 / 100
799 ms 49920 KB
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 2e3 + 100;

int sign(ll x) {return (x>0) - (x<0); }
struct PT {
	int x, y, c;
	PT() {}
	PT(int xx, int yy, int cc) : x(xx), y(yy), c(cc) {}
	PT operator-(const PT &o) const {return PT(x-o.x, y-o.y, 0); }
	ll cross(const PT &o) const{return 1ll * x * o.y - 1ll * y * o.x;}
	ll dot(const PT &o) const {return 1ll * x * o.x + 1ll * y * o.y;}
	int ccw(const PT &o) const {return sign(cross(o));}
	bool operator<(const PT &o) const {
		if(y != o.y) return y < o.y;
		return x < o.x;
	}
};
vector<PT> Ps;

struct LN {
	PT sl; int p;
	int i, j;
	LN(int ii, int jj) : i(ii), j(jj) {
		sl = Ps[j] - Ps[i];
		if(sl.y > 0 || sl.y == 0 && sl.x > 0) p = 0;
		else p = 1;
	}
	bool operator<(const LN &o) const {
		if(p != o.p) return p < o.p;
		if(sl.ccw(o.sl) != 0) return sl.ccw(o.sl) > 0;
		if(sl.dot(Ps[i]) != sl.dot(Ps[o.i])) return sl.dot(Ps[i]) < sl.dot(Ps[o.i]);
		return sl.dot(Ps[j]) < sl.dot(Ps[o.j]);
	}
};
vector<LN> Ls;

struct IDX {
	int P; vector<ll> l, r, s, m;
	IDX() {}
	IDX(int n) {
		for(P=1; P<n; P<<=1);
		l = r = s = m = vector<ll>(2*P, 0);
	}
	void update(int v, int k) {
		v += P;
		if(k >= 0) l[v] = r[v] = m[v] = s[v] = k;
		else l[v] = r[v] = m[v] = 0, s[v] = k;
		while(v >>= 1) {
			l[v] = max(l[v*2], s[v*2] + l[v*2+1]);
			r[v] = max(r[v*2+1], s[v*2+1] + r[v*2]);
			s[v] = s[v*2] + s[v*2+1];
			m[v] = max(r[v*2] + l[v*2+1], max(m[v*2], m[v*2+1]));
		}
	}
};

int N, Ix[MAX_N];
int main() {
	cin >> N;
	REP(i, N) {
		int x, y, c; scanf("%d%d%d", &x, &y, &c);
		Ps.push_back(PT(x, y, c));
	}
	sort(ALL(Ps));
	REP(i, N) REP(j, N) if(i < j) Ls.push_back(LN(i, j));
	sort(ALL(Ls));
//	for(LN &l : Ls) printf("[%d %d]\n", l.i, l.j);
	REP(i, N) Ix[i] = i;

	IDX idx = IDX(N);
	REP(i, N) idx.update(i, Ps[i].c);
	ll ans = idx.m[1];
//	for(int k=0; k<N; k++) printf("[%d %d %d] ", Ps[k].x, Ps[k].y, Ps[k].c); puts("");
	for(int i=0, j=0; i<SZ(Ls); i=j) {
		while(j < SZ(Ls) && Ls[i].sl.ccw(Ls[j].sl) == 0) {
			int &x = Ix[Ls[j].i], &y = Ix[Ls[j].j];
//			printf("swap %d %d\n", x, y);
			swap(Ps[x], Ps[y]);
			swap(x, y);
			idx.update(x, Ps[x].c);
			idx.update(y, Ps[y].c);
			j++;
		}
		ans = max(ans, idx.m[1]);
//		for(int k=0; k<N; k++) printf("[%d %d %d] ", Ps[k].x, Ps[k].y, Ps[k].c); puts("");
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

bulldozer.cpp: In constructor 'LN::LN(int, int)':
bulldozer.cpp:40:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   if(sl.y > 0 || sl.y == 0 && sl.x > 0) p = 0;
                  ~~~~~~~~~~^~~~~~~~~~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:76:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y, c; scanf("%d%d%d", &x, &y, &c);
                ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 21 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 3 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 4 ms 640 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 3 ms 640 KB Output is correct
26 Correct 3 ms 640 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 3 ms 640 KB Output is correct
29 Correct 3 ms 640 KB Output is correct
30 Correct 3 ms 640 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 3 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 4 ms 640 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 3 ms 640 KB Output is correct
26 Correct 3 ms 640 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 3 ms 640 KB Output is correct
29 Correct 3 ms 640 KB Output is correct
30 Correct 3 ms 640 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 3 ms 640 KB Output is correct
33 Correct 691 ms 49760 KB Output is correct
34 Correct 714 ms 49880 KB Output is correct
35 Correct 722 ms 49732 KB Output is correct
36 Correct 722 ms 49756 KB Output is correct
37 Correct 693 ms 49864 KB Output is correct
38 Correct 749 ms 49732 KB Output is correct
39 Correct 770 ms 49732 KB Output is correct
40 Correct 732 ms 49732 KB Output is correct
41 Correct 702 ms 49696 KB Output is correct
42 Correct 702 ms 49872 KB Output is correct
43 Correct 679 ms 49732 KB Output is correct
44 Correct 724 ms 49756 KB Output is correct
45 Correct 799 ms 49732 KB Output is correct
46 Correct 699 ms 49732 KB Output is correct
47 Correct 725 ms 49780 KB Output is correct
48 Correct 713 ms 49732 KB Output is correct
49 Correct 702 ms 49796 KB Output is correct
50 Correct 698 ms 49736 KB Output is correct
51 Correct 708 ms 49904 KB Output is correct
52 Correct 721 ms 49708 KB Output is correct
53 Correct 714 ms 49732 KB Output is correct
54 Correct 688 ms 49732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 3 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 4 ms 640 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 3 ms 640 KB Output is correct
26 Correct 3 ms 640 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 3 ms 640 KB Output is correct
29 Correct 3 ms 640 KB Output is correct
30 Correct 3 ms 640 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 3 ms 640 KB Output is correct
33 Correct 691 ms 49760 KB Output is correct
34 Correct 714 ms 49880 KB Output is correct
35 Correct 722 ms 49732 KB Output is correct
36 Correct 722 ms 49756 KB Output is correct
37 Correct 693 ms 49864 KB Output is correct
38 Correct 749 ms 49732 KB Output is correct
39 Correct 770 ms 49732 KB Output is correct
40 Correct 732 ms 49732 KB Output is correct
41 Correct 702 ms 49696 KB Output is correct
42 Correct 702 ms 49872 KB Output is correct
43 Correct 679 ms 49732 KB Output is correct
44 Correct 724 ms 49756 KB Output is correct
45 Correct 799 ms 49732 KB Output is correct
46 Correct 699 ms 49732 KB Output is correct
47 Correct 725 ms 49780 KB Output is correct
48 Correct 713 ms 49732 KB Output is correct
49 Correct 702 ms 49796 KB Output is correct
50 Correct 698 ms 49736 KB Output is correct
51 Correct 708 ms 49904 KB Output is correct
52 Correct 721 ms 49708 KB Output is correct
53 Correct 714 ms 49732 KB Output is correct
54 Correct 688 ms 49732 KB Output is correct
55 Correct 689 ms 49796 KB Output is correct
56 Correct 678 ms 49792 KB Output is correct
57 Correct 690 ms 49756 KB Output is correct
58 Correct 703 ms 49764 KB Output is correct
59 Correct 693 ms 49732 KB Output is correct
60 Correct 706 ms 49744 KB Output is correct
61 Correct 742 ms 49732 KB Output is correct
62 Correct 712 ms 49700 KB Output is correct
63 Correct 703 ms 49728 KB Output is correct
64 Correct 686 ms 49732 KB Output is correct
65 Correct 704 ms 49732 KB Output is correct
66 Correct 707 ms 49740 KB Output is correct
67 Correct 680 ms 49704 KB Output is correct
68 Correct 691 ms 49860 KB Output is correct
69 Correct 710 ms 49732 KB Output is correct
70 Correct 707 ms 49732 KB Output is correct
71 Correct 737 ms 49712 KB Output is correct
72 Correct 707 ms 49888 KB Output is correct
73 Correct 709 ms 49820 KB Output is correct
74 Correct 696 ms 49704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 21 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 3 ms 640 KB Output is correct
17 Correct 3 ms 640 KB Output is correct
18 Correct 3 ms 640 KB Output is correct
19 Correct 3 ms 640 KB Output is correct
20 Correct 3 ms 640 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 3 ms 640 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 3 ms 256 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2 ms 256 KB Output is correct
35 Correct 2 ms 256 KB Output is correct
36 Correct 4 ms 640 KB Output is correct
37 Correct 3 ms 640 KB Output is correct
38 Correct 4 ms 640 KB Output is correct
39 Correct 3 ms 640 KB Output is correct
40 Correct 3 ms 640 KB Output is correct
41 Correct 3 ms 640 KB Output is correct
42 Correct 3 ms 640 KB Output is correct
43 Correct 3 ms 640 KB Output is correct
44 Correct 3 ms 640 KB Output is correct
45 Correct 3 ms 640 KB Output is correct
46 Correct 3 ms 640 KB Output is correct
47 Correct 3 ms 640 KB Output is correct
48 Correct 691 ms 49760 KB Output is correct
49 Correct 714 ms 49880 KB Output is correct
50 Correct 722 ms 49732 KB Output is correct
51 Correct 722 ms 49756 KB Output is correct
52 Correct 693 ms 49864 KB Output is correct
53 Correct 749 ms 49732 KB Output is correct
54 Correct 770 ms 49732 KB Output is correct
55 Correct 732 ms 49732 KB Output is correct
56 Correct 702 ms 49696 KB Output is correct
57 Correct 702 ms 49872 KB Output is correct
58 Correct 679 ms 49732 KB Output is correct
59 Correct 724 ms 49756 KB Output is correct
60 Correct 799 ms 49732 KB Output is correct
61 Correct 699 ms 49732 KB Output is correct
62 Correct 725 ms 49780 KB Output is correct
63 Correct 713 ms 49732 KB Output is correct
64 Correct 702 ms 49796 KB Output is correct
65 Correct 698 ms 49736 KB Output is correct
66 Correct 708 ms 49904 KB Output is correct
67 Correct 721 ms 49708 KB Output is correct
68 Correct 714 ms 49732 KB Output is correct
69 Correct 688 ms 49732 KB Output is correct
70 Correct 689 ms 49796 KB Output is correct
71 Correct 678 ms 49792 KB Output is correct
72 Correct 690 ms 49756 KB Output is correct
73 Correct 703 ms 49764 KB Output is correct
74 Correct 693 ms 49732 KB Output is correct
75 Correct 706 ms 49744 KB Output is correct
76 Correct 742 ms 49732 KB Output is correct
77 Correct 712 ms 49700 KB Output is correct
78 Correct 703 ms 49728 KB Output is correct
79 Correct 686 ms 49732 KB Output is correct
80 Correct 704 ms 49732 KB Output is correct
81 Correct 707 ms 49740 KB Output is correct
82 Correct 680 ms 49704 KB Output is correct
83 Correct 691 ms 49860 KB Output is correct
84 Correct 710 ms 49732 KB Output is correct
85 Correct 707 ms 49732 KB Output is correct
86 Correct 737 ms 49712 KB Output is correct
87 Correct 707 ms 49888 KB Output is correct
88 Correct 709 ms 49820 KB Output is correct
89 Correct 696 ms 49704 KB Output is correct
90 Correct 688 ms 49776 KB Output is correct
91 Correct 679 ms 49784 KB Output is correct
92 Correct 696 ms 49784 KB Output is correct
93 Correct 692 ms 49712 KB Output is correct
94 Correct 683 ms 49704 KB Output is correct
95 Correct 702 ms 49732 KB Output is correct
96 Correct 681 ms 49776 KB Output is correct
97 Correct 712 ms 49740 KB Output is correct
98 Correct 734 ms 49728 KB Output is correct
99 Correct 725 ms 49708 KB Output is correct
100 Correct 724 ms 49704 KB Output is correct
101 Correct 751 ms 49604 KB Output is correct
102 Correct 762 ms 49804 KB Output is correct
103 Correct 722 ms 49920 KB Output is correct
104 Correct 762 ms 49732 KB Output is correct
105 Correct 735 ms 49808 KB Output is correct
106 Correct 713 ms 49800 KB Output is correct
107 Correct 700 ms 49732 KB Output is correct
108 Correct 717 ms 49736 KB Output is correct
109 Correct 782 ms 49720 KB Output is correct
110 Correct 747 ms 49704 KB Output is correct
111 Correct 745 ms 49752 KB Output is correct
112 Correct 755 ms 49752 KB Output is correct
113 Correct 737 ms 49716 KB Output is correct
114 Correct 722 ms 49884 KB Output is correct
115 Correct 721 ms 49704 KB Output is correct
116 Correct 722 ms 49732 KB Output is correct
117 Correct 748 ms 49704 KB Output is correct
118 Correct 727 ms 49892 KB Output is correct
119 Correct 720 ms 49700 KB Output is correct
120 Correct 2 ms 356 KB Output is correct
121 Correct 2 ms 384 KB Output is correct
122 Correct 695 ms 49804 KB Output is correct
123 Correct 684 ms 49812 KB Output is correct
124 Correct 684 ms 49756 KB Output is correct
125 Correct 704 ms 49780 KB Output is correct
126 Correct 676 ms 49776 KB Output is correct
127 Correct 694 ms 49732 KB Output is correct
128 Correct 706 ms 49704 KB Output is correct
129 Correct 697 ms 49700 KB Output is correct
130 Correct 693 ms 49756 KB Output is correct
131 Correct 694 ms 49736 KB Output is correct
132 Correct 714 ms 49704 KB Output is correct
133 Correct 700 ms 49768 KB Output is correct