답안 #101231

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
101231 2019-03-17T21:04:02 Z jasony123123 Bulldozer (JOI17_bulldozer) C++11
100 / 100
971 ms 50160 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define v vector
#define mp make_pair
typedef long long ll;
typedef pair<int, int > pii;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }
void io() {
#ifdef LOCAL_PROJECT 
	freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else 
#endif 
	ios_base::sync_with_stdio(false); cin.tie(NULL);
}
/****************************************************************/
const int MAXN = 2000;
int N, pos[2000];
ll x[2000], y[2000], w[2000];

struct Node {
	ll lsum, rsum, bsum, esum;
	Node() {
		lsum = rsum = bsum = esum = 0LL;
	}
	Node(ll val) {
		lsum = rsum = bsum = max(0LL, val);
		esum = val;
	}
	Node(Node &a, Node &b) {
		lsum = max(a.lsum, a.esum + b.lsum);
		rsum = max(b.rsum, b.esum + a.rsum);
		bsum = max(a.bsum, max(b.bsum, a.rsum + b.lsum));
		esum = a.esum + b.esum;
	}
};
struct Seg {
	int SZ = 1 << 12;
	Node data[1 << 13];

	void set(int x, ll val) {
		data[x + SZ] = Node(val);
	}
	void build() {
		for (int i = SZ - 1; i > 0; i--)
			data[i] = Node(data[i * 2], data[i * 2 + 1]);
	}
	void update(int x, ll val) {
		set(x, val);
		x += SZ;
		x /= 2;
		while (x) {
			data[x] = Node(data[x * 2], data[x * 2 + 1]);
			x /= 2;
		}
	}
	ll query() {
		return data[1].bsum;
	}

	//int data[2000];

	//void set(int x, int val) {
	//	data[x] = val;
	//}
	//void build() {

	//}
	//void update(int x, int val) {
	//	data[x] = val;
	//}
	//ll query() {
	//	//	cout << "Query: ";
	//	//	FOR(i, 0, N) cout << data[i] << " ";
	//	ll best = 0;
	//	FOR(i, 0, N) FOR(j, i, N) {
	//		ll tmp = 0;
	//		FORE(x, i, j) tmp += data[x];
	//		maxx(best, tmp);
	//	}
	//	//	cout << ":: " << best << "\n";
	//	return best;
	//}
} tree;

struct upd {
	ll vx, vy;
	int ia, ib;
	upd(ll _vx, ll _vy, int _a, int _b) : vx(_vx), vy(_vy), ia(_a), ib(_b) {}
};
v<upd> lines;

void perform_swap(int i, int j) {
	//	cout << "Swapping " << i << " " << j << "\n";
	swap(pos[i], pos[j]);
	tree.update(pos[i], w[i]);
	tree.update(pos[j], w[j]);
}

void setup() {
	cin >> N;
	v<int> pnts(N);
	FOR(i, 0, N) {
		cin >> x[i] >> y[i] >> w[i];
		pnts[i] = i;
	}
	sort(all(pnts), [](int &i, int &j) {
		return mp(x[i], y[i]) < mp(x[j], y[j]);
	});
	FOR(i, 0, N) {
		pos[pnts[i]] = i;
		tree.update(i, w[pnts[i]]);
	}
}

int main() {
	io();
	setup();
	FOR(i, 0, N) FOR(j, 0, N) if (x[i] < x[j])
		lines.push_back(upd(x[j] - x[i], y[j] - y[i], i, j));

	sort(all(lines), [](upd &a, upd &b) {
		if (a.vy*b.vx == b.vy*a.vx) {
		//	assert(0);
			return mp(x[a.ia], x[a.ib]) > mp(x[b.ia], x[b.ib]);
		}
		return a.vy*b.vx > b.vy*a.vx;
	});
	reverse(all(lines));

	ll best = tree.query();
	for (int i = 0; i < lines.size(); ) {
		ll curx = lines[i].vx, cury = lines[i].vy;
		while (i < lines.size() && cury*lines[i].vx == curx*lines[i].vy) {
			perform_swap(lines[i].ia, lines[i].ib);
			i++;
		}
		maxx(best, tree.query());
	}
	cout << best << "\n";
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:136:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < lines.size(); ) {
                  ~~^~~~~~~~~~~~~~
bulldozer.cpp:138:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (i < lines.size() && cury*lines[i].vx == curx*lines[i].vy) {
          ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 896 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 4 ms 992 KB Output is correct
4 Correct 4 ms 896 KB Output is correct
5 Correct 4 ms 896 KB Output is correct
6 Correct 4 ms 896 KB Output is correct
7 Correct 3 ms 896 KB Output is correct
8 Correct 0 ms 896 KB Output is correct
9 Correct 4 ms 896 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 896 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 4 ms 896 KB Output is correct
4 Correct 4 ms 896 KB Output is correct
5 Correct 4 ms 896 KB Output is correct
6 Correct 4 ms 896 KB Output is correct
7 Correct 4 ms 868 KB Output is correct
8 Correct 4 ms 896 KB Output is correct
9 Correct 4 ms 896 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 2 ms 640 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 4 ms 896 KB Output is correct
22 Correct 4 ms 896 KB Output is correct
23 Correct 4 ms 896 KB Output is correct
24 Correct 4 ms 896 KB Output is correct
25 Correct 3 ms 896 KB Output is correct
26 Correct 4 ms 896 KB Output is correct
27 Correct 4 ms 960 KB Output is correct
28 Correct 3 ms 896 KB Output is correct
29 Correct 4 ms 896 KB Output is correct
30 Correct 4 ms 896 KB Output is correct
31 Correct 4 ms 896 KB Output is correct
32 Correct 4 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 896 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 4 ms 896 KB Output is correct
4 Correct 4 ms 896 KB Output is correct
5 Correct 4 ms 896 KB Output is correct
6 Correct 4 ms 896 KB Output is correct
7 Correct 4 ms 868 KB Output is correct
8 Correct 4 ms 896 KB Output is correct
9 Correct 4 ms 896 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 2 ms 640 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 4 ms 896 KB Output is correct
22 Correct 4 ms 896 KB Output is correct
23 Correct 4 ms 896 KB Output is correct
24 Correct 4 ms 896 KB Output is correct
25 Correct 3 ms 896 KB Output is correct
26 Correct 4 ms 896 KB Output is correct
27 Correct 4 ms 960 KB Output is correct
28 Correct 3 ms 896 KB Output is correct
29 Correct 4 ms 896 KB Output is correct
30 Correct 4 ms 896 KB Output is correct
31 Correct 4 ms 896 KB Output is correct
32 Correct 4 ms 896 KB Output is correct
33 Correct 884 ms 50096 KB Output is correct
34 Correct 873 ms 49968 KB Output is correct
35 Correct 872 ms 50076 KB Output is correct
36 Correct 879 ms 50028 KB Output is correct
37 Correct 908 ms 50032 KB Output is correct
38 Correct 859 ms 49980 KB Output is correct
39 Correct 877 ms 50012 KB Output is correct
40 Correct 852 ms 50064 KB Output is correct
41 Correct 866 ms 50152 KB Output is correct
42 Correct 861 ms 49964 KB Output is correct
43 Correct 847 ms 50000 KB Output is correct
44 Correct 848 ms 49988 KB Output is correct
45 Correct 845 ms 49964 KB Output is correct
46 Correct 857 ms 49964 KB Output is correct
47 Correct 868 ms 49964 KB Output is correct
48 Correct 871 ms 50064 KB Output is correct
49 Correct 856 ms 50092 KB Output is correct
50 Correct 877 ms 50092 KB Output is correct
51 Correct 857 ms 49988 KB Output is correct
52 Correct 855 ms 50088 KB Output is correct
53 Correct 851 ms 50104 KB Output is correct
54 Correct 846 ms 50032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 896 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 4 ms 896 KB Output is correct
4 Correct 4 ms 896 KB Output is correct
5 Correct 4 ms 896 KB Output is correct
6 Correct 4 ms 896 KB Output is correct
7 Correct 4 ms 868 KB Output is correct
8 Correct 4 ms 896 KB Output is correct
9 Correct 4 ms 896 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 2 ms 640 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 4 ms 896 KB Output is correct
22 Correct 4 ms 896 KB Output is correct
23 Correct 4 ms 896 KB Output is correct
24 Correct 4 ms 896 KB Output is correct
25 Correct 3 ms 896 KB Output is correct
26 Correct 4 ms 896 KB Output is correct
27 Correct 4 ms 960 KB Output is correct
28 Correct 3 ms 896 KB Output is correct
29 Correct 4 ms 896 KB Output is correct
30 Correct 4 ms 896 KB Output is correct
31 Correct 4 ms 896 KB Output is correct
32 Correct 4 ms 896 KB Output is correct
33 Correct 884 ms 50096 KB Output is correct
34 Correct 873 ms 49968 KB Output is correct
35 Correct 872 ms 50076 KB Output is correct
36 Correct 879 ms 50028 KB Output is correct
37 Correct 908 ms 50032 KB Output is correct
38 Correct 859 ms 49980 KB Output is correct
39 Correct 877 ms 50012 KB Output is correct
40 Correct 852 ms 50064 KB Output is correct
41 Correct 866 ms 50152 KB Output is correct
42 Correct 861 ms 49964 KB Output is correct
43 Correct 847 ms 50000 KB Output is correct
44 Correct 848 ms 49988 KB Output is correct
45 Correct 845 ms 49964 KB Output is correct
46 Correct 857 ms 49964 KB Output is correct
47 Correct 868 ms 49964 KB Output is correct
48 Correct 871 ms 50064 KB Output is correct
49 Correct 856 ms 50092 KB Output is correct
50 Correct 877 ms 50092 KB Output is correct
51 Correct 857 ms 49988 KB Output is correct
52 Correct 855 ms 50088 KB Output is correct
53 Correct 851 ms 50104 KB Output is correct
54 Correct 846 ms 50032 KB Output is correct
55 Correct 847 ms 49992 KB Output is correct
56 Correct 860 ms 50064 KB Output is correct
57 Correct 862 ms 49964 KB Output is correct
58 Correct 845 ms 49964 KB Output is correct
59 Correct 847 ms 50028 KB Output is correct
60 Correct 849 ms 50008 KB Output is correct
61 Correct 868 ms 50056 KB Output is correct
62 Correct 865 ms 50064 KB Output is correct
63 Correct 971 ms 50012 KB Output is correct
64 Correct 865 ms 50016 KB Output is correct
65 Correct 859 ms 50080 KB Output is correct
66 Correct 900 ms 50048 KB Output is correct
67 Correct 887 ms 50072 KB Output is correct
68 Correct 867 ms 50060 KB Output is correct
69 Correct 876 ms 50136 KB Output is correct
70 Correct 865 ms 49968 KB Output is correct
71 Correct 867 ms 49996 KB Output is correct
72 Correct 927 ms 49964 KB Output is correct
73 Correct 889 ms 50008 KB Output is correct
74 Correct 859 ms 50044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 896 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 4 ms 992 KB Output is correct
4 Correct 4 ms 896 KB Output is correct
5 Correct 4 ms 896 KB Output is correct
6 Correct 4 ms 896 KB Output is correct
7 Correct 3 ms 896 KB Output is correct
8 Correct 0 ms 896 KB Output is correct
9 Correct 4 ms 896 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 4 ms 896 KB Output is correct
17 Correct 4 ms 896 KB Output is correct
18 Correct 4 ms 896 KB Output is correct
19 Correct 4 ms 896 KB Output is correct
20 Correct 4 ms 896 KB Output is correct
21 Correct 4 ms 896 KB Output is correct
22 Correct 4 ms 868 KB Output is correct
23 Correct 4 ms 896 KB Output is correct
24 Correct 4 ms 896 KB Output is correct
25 Correct 4 ms 896 KB Output is correct
26 Correct 2 ms 640 KB Output is correct
27 Correct 2 ms 640 KB Output is correct
28 Correct 2 ms 640 KB Output is correct
29 Correct 2 ms 640 KB Output is correct
30 Correct 2 ms 640 KB Output is correct
31 Correct 2 ms 640 KB Output is correct
32 Correct 2 ms 640 KB Output is correct
33 Correct 2 ms 640 KB Output is correct
34 Correct 2 ms 640 KB Output is correct
35 Correct 2 ms 640 KB Output is correct
36 Correct 4 ms 896 KB Output is correct
37 Correct 4 ms 896 KB Output is correct
38 Correct 4 ms 896 KB Output is correct
39 Correct 4 ms 896 KB Output is correct
40 Correct 3 ms 896 KB Output is correct
41 Correct 4 ms 896 KB Output is correct
42 Correct 4 ms 960 KB Output is correct
43 Correct 3 ms 896 KB Output is correct
44 Correct 4 ms 896 KB Output is correct
45 Correct 4 ms 896 KB Output is correct
46 Correct 4 ms 896 KB Output is correct
47 Correct 4 ms 896 KB Output is correct
48 Correct 884 ms 50096 KB Output is correct
49 Correct 873 ms 49968 KB Output is correct
50 Correct 872 ms 50076 KB Output is correct
51 Correct 879 ms 50028 KB Output is correct
52 Correct 908 ms 50032 KB Output is correct
53 Correct 859 ms 49980 KB Output is correct
54 Correct 877 ms 50012 KB Output is correct
55 Correct 852 ms 50064 KB Output is correct
56 Correct 866 ms 50152 KB Output is correct
57 Correct 861 ms 49964 KB Output is correct
58 Correct 847 ms 50000 KB Output is correct
59 Correct 848 ms 49988 KB Output is correct
60 Correct 845 ms 49964 KB Output is correct
61 Correct 857 ms 49964 KB Output is correct
62 Correct 868 ms 49964 KB Output is correct
63 Correct 871 ms 50064 KB Output is correct
64 Correct 856 ms 50092 KB Output is correct
65 Correct 877 ms 50092 KB Output is correct
66 Correct 857 ms 49988 KB Output is correct
67 Correct 855 ms 50088 KB Output is correct
68 Correct 851 ms 50104 KB Output is correct
69 Correct 846 ms 50032 KB Output is correct
70 Correct 847 ms 49992 KB Output is correct
71 Correct 860 ms 50064 KB Output is correct
72 Correct 862 ms 49964 KB Output is correct
73 Correct 845 ms 49964 KB Output is correct
74 Correct 847 ms 50028 KB Output is correct
75 Correct 849 ms 50008 KB Output is correct
76 Correct 868 ms 50056 KB Output is correct
77 Correct 865 ms 50064 KB Output is correct
78 Correct 971 ms 50012 KB Output is correct
79 Correct 865 ms 50016 KB Output is correct
80 Correct 859 ms 50080 KB Output is correct
81 Correct 900 ms 50048 KB Output is correct
82 Correct 887 ms 50072 KB Output is correct
83 Correct 867 ms 50060 KB Output is correct
84 Correct 876 ms 50136 KB Output is correct
85 Correct 865 ms 49968 KB Output is correct
86 Correct 867 ms 49996 KB Output is correct
87 Correct 927 ms 49964 KB Output is correct
88 Correct 889 ms 50008 KB Output is correct
89 Correct 859 ms 50044 KB Output is correct
90 Correct 888 ms 50092 KB Output is correct
91 Correct 888 ms 49980 KB Output is correct
92 Correct 876 ms 50160 KB Output is correct
93 Correct 876 ms 50064 KB Output is correct
94 Correct 894 ms 50052 KB Output is correct
95 Correct 884 ms 50004 KB Output is correct
96 Correct 889 ms 50004 KB Output is correct
97 Correct 864 ms 50008 KB Output is correct
98 Correct 858 ms 50088 KB Output is correct
99 Correct 854 ms 49964 KB Output is correct
100 Correct 412 ms 25472 KB Output is correct
101 Correct 421 ms 25428 KB Output is correct
102 Correct 418 ms 25412 KB Output is correct
103 Correct 415 ms 25448 KB Output is correct
104 Correct 416 ms 25428 KB Output is correct
105 Correct 573 ms 49996 KB Output is correct
106 Correct 579 ms 49968 KB Output is correct
107 Correct 599 ms 50004 KB Output is correct
108 Correct 572 ms 50092 KB Output is correct
109 Correct 577 ms 49992 KB Output is correct
110 Correct 830 ms 49964 KB Output is correct
111 Correct 802 ms 49964 KB Output is correct
112 Correct 822 ms 50068 KB Output is correct
113 Correct 816 ms 50092 KB Output is correct
114 Correct 804 ms 50084 KB Output is correct
115 Correct 844 ms 50012 KB Output is correct
116 Correct 807 ms 50044 KB Output is correct
117 Correct 800 ms 50008 KB Output is correct
118 Correct 803 ms 49964 KB Output is correct
119 Correct 820 ms 49964 KB Output is correct
120 Correct 2 ms 640 KB Output is correct
121 Correct 2 ms 640 KB Output is correct
122 Correct 889 ms 50092 KB Output is correct
123 Correct 886 ms 49964 KB Output is correct
124 Correct 943 ms 49964 KB Output is correct
125 Correct 935 ms 49968 KB Output is correct
126 Correct 900 ms 50092 KB Output is correct
127 Correct 886 ms 49992 KB Output is correct
128 Correct 890 ms 49968 KB Output is correct
129 Correct 872 ms 49964 KB Output is correct
130 Correct 879 ms 49992 KB Output is correct
131 Correct 895 ms 50092 KB Output is correct
132 Correct 874 ms 49968 KB Output is correct
133 Correct 870 ms 50024 KB Output is correct