답안 #1078762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078762 2024-08-28T05:56:43 Z qwerasdfzxcl Bulldozer (JOI17_bulldozer) C++17
100 / 100
664 ms 17344 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

struct Node{
	ll prf, suf, sum, ans;
	Node(){}
	Node(ll x){
		if (x >= 0) prf = suf = sum = ans = x;
		else prf = suf = ans = 0, sum = x;
	}
	Node(ll _p, ll _s, ll _ss, ll _a): prf(_p), suf(_s), sum(_ss), ans(_a) {}

	Node operator + (const Node &N) const{
		return Node(max(prf, sum + N.prf), max(N.suf, suf + N.sum), sum + N.sum, max({ans, N.ans, suf + N.prf}));
	}
};

struct Seg{
	Node tree[4096];
	int sz, _n;

	void debug(){
		printf("A: ");
		for (int i=1;i<=_n;i++) printf("%lld ", tree[sz+i].sum);
		printf("\n");
		printf("ans = %lld\n", tree[1].ans);
		printf("\n");
	}

	void init(int n, array<int, 4> a[]){
		sz = 2048, _n = n;
		fill(tree, tree+sz*2, Node(0, 0, 0, 0));
		for (int i=1;i<=n;i++) tree[sz+i] = Node(a[i][2]);
		for (int i=sz-1;i;i--) tree[i] = tree[i<<1] + tree[i<<1|1];
	}

	void swap(int p, int q){
		p += sz, q += sz;
		std::swap(tree[p], tree[q]);
		for (p>>=1,q>>=1;p>0||q>0;p>>=1,q>>=1){
			tree[p] = tree[p<<1] + tree[p<<1|1];
			if (p!=q) tree[q] = tree[q<<1] + tree[q<<1|1];
		}
	}
}tree;

array<int, 4> a[2020];

int ccw(const array<int, 2> &P, const array<int, 2> &Q){
	ll ret = (ll)(a[P[1]][0] - a[P[0]][0]) * (a[Q[1]][1] - a[Q[0]][1]) - (ll)(a[P[1]][1] - a[P[0]][1]) * (a[Q[1]][0] - a[Q[0]][0]);
	if (ret > 0) return 1;
	if (ret < 0) return -1;
	return 0;
}

bool cmp(const array<int, 2> &P, const array<int, 2> &Q){
	int ret1 = ccw(P, Q);
	if (ret1) return ret1 > 0;
	return P < Q;
}

int main(){
	int n;
	scanf("%d", &n);

	for (int i=1;i<=n;i++){
		scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]);
	}

	sort(a+1, a+n+1);
	for (int i=1;i<=n;i++) a[i][3] = i; // ord

	vector<array<int, 2>> Ev;

	for (int i=1;i<=n;i++){
		for (int j=i+1;j<=n;j++){
			int ii = i, jj = j; // ii -> jj
			if ((a[i][0] < a[j][0]) || (a[i][0]==a[j][0] && a[i][1] < a[j][1])) swap(ii, jj);
			Ev.push_back({ii, jj});
		}
	}

	sort(Ev.begin(), Ev.end(), cmp);
	tree.init(n, a);
	ll ans = tree.tree[1].ans;

	for (int l=0,r;l<(int)Ev.size();l=r){
		for (r=l;r<(int)Ev.size() && !ccw(Ev[l], Ev[r]);r++);
		for (int i=l;i<r;i++){
			int &p = a[Ev[i][0]][3], &q = a[Ev[i][1]][3];
			assert(abs(p-q) == 1);
			
			tree.swap(p, q);
			swap(p, q);
		}

		ans = max(ans, tree.tree[1].ans);
	}

	printf("%lld\n", ans);
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:66:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
bulldozer.cpp:69:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |   scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 444 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 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 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 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 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 627 ms 17088 KB Output is correct
34 Correct 594 ms 17088 KB Output is correct
35 Correct 631 ms 17092 KB Output is correct
36 Correct 591 ms 17076 KB Output is correct
37 Correct 624 ms 17088 KB Output is correct
38 Correct 584 ms 17344 KB Output is correct
39 Correct 610 ms 17092 KB Output is correct
40 Correct 596 ms 17096 KB Output is correct
41 Correct 607 ms 17088 KB Output is correct
42 Correct 622 ms 17092 KB Output is correct
43 Correct 603 ms 17080 KB Output is correct
44 Correct 614 ms 17088 KB Output is correct
45 Correct 583 ms 17092 KB Output is correct
46 Correct 589 ms 17092 KB Output is correct
47 Correct 592 ms 17092 KB Output is correct
48 Correct 581 ms 17092 KB Output is correct
49 Correct 609 ms 17088 KB Output is correct
50 Correct 611 ms 17344 KB Output is correct
51 Correct 600 ms 17088 KB Output is correct
52 Correct 586 ms 17088 KB Output is correct
53 Correct 592 ms 17088 KB Output is correct
54 Correct 588 ms 17092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 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 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 627 ms 17088 KB Output is correct
34 Correct 594 ms 17088 KB Output is correct
35 Correct 631 ms 17092 KB Output is correct
36 Correct 591 ms 17076 KB Output is correct
37 Correct 624 ms 17088 KB Output is correct
38 Correct 584 ms 17344 KB Output is correct
39 Correct 610 ms 17092 KB Output is correct
40 Correct 596 ms 17096 KB Output is correct
41 Correct 607 ms 17088 KB Output is correct
42 Correct 622 ms 17092 KB Output is correct
43 Correct 603 ms 17080 KB Output is correct
44 Correct 614 ms 17088 KB Output is correct
45 Correct 583 ms 17092 KB Output is correct
46 Correct 589 ms 17092 KB Output is correct
47 Correct 592 ms 17092 KB Output is correct
48 Correct 581 ms 17092 KB Output is correct
49 Correct 609 ms 17088 KB Output is correct
50 Correct 611 ms 17344 KB Output is correct
51 Correct 600 ms 17088 KB Output is correct
52 Correct 586 ms 17088 KB Output is correct
53 Correct 592 ms 17088 KB Output is correct
54 Correct 588 ms 17092 KB Output is correct
55 Correct 591 ms 17084 KB Output is correct
56 Correct 593 ms 17088 KB Output is correct
57 Correct 592 ms 17092 KB Output is correct
58 Correct 603 ms 17092 KB Output is correct
59 Correct 601 ms 17092 KB Output is correct
60 Correct 599 ms 17036 KB Output is correct
61 Correct 579 ms 17088 KB Output is correct
62 Correct 610 ms 17092 KB Output is correct
63 Correct 590 ms 17088 KB Output is correct
64 Correct 610 ms 17092 KB Output is correct
65 Correct 604 ms 17064 KB Output is correct
66 Correct 583 ms 17092 KB Output is correct
67 Correct 605 ms 17092 KB Output is correct
68 Correct 591 ms 17092 KB Output is correct
69 Correct 624 ms 17092 KB Output is correct
70 Correct 600 ms 17092 KB Output is correct
71 Correct 581 ms 17088 KB Output is correct
72 Correct 599 ms 16964 KB Output is correct
73 Correct 603 ms 17088 KB Output is correct
74 Correct 647 ms 17080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 444 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 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 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 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 2 ms 600 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 2 ms 600 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 627 ms 17088 KB Output is correct
49 Correct 594 ms 17088 KB Output is correct
50 Correct 631 ms 17092 KB Output is correct
51 Correct 591 ms 17076 KB Output is correct
52 Correct 624 ms 17088 KB Output is correct
53 Correct 584 ms 17344 KB Output is correct
54 Correct 610 ms 17092 KB Output is correct
55 Correct 596 ms 17096 KB Output is correct
56 Correct 607 ms 17088 KB Output is correct
57 Correct 622 ms 17092 KB Output is correct
58 Correct 603 ms 17080 KB Output is correct
59 Correct 614 ms 17088 KB Output is correct
60 Correct 583 ms 17092 KB Output is correct
61 Correct 589 ms 17092 KB Output is correct
62 Correct 592 ms 17092 KB Output is correct
63 Correct 581 ms 17092 KB Output is correct
64 Correct 609 ms 17088 KB Output is correct
65 Correct 611 ms 17344 KB Output is correct
66 Correct 600 ms 17088 KB Output is correct
67 Correct 586 ms 17088 KB Output is correct
68 Correct 592 ms 17088 KB Output is correct
69 Correct 588 ms 17092 KB Output is correct
70 Correct 591 ms 17084 KB Output is correct
71 Correct 593 ms 17088 KB Output is correct
72 Correct 592 ms 17092 KB Output is correct
73 Correct 603 ms 17092 KB Output is correct
74 Correct 601 ms 17092 KB Output is correct
75 Correct 599 ms 17036 KB Output is correct
76 Correct 579 ms 17088 KB Output is correct
77 Correct 610 ms 17092 KB Output is correct
78 Correct 590 ms 17088 KB Output is correct
79 Correct 610 ms 17092 KB Output is correct
80 Correct 604 ms 17064 KB Output is correct
81 Correct 583 ms 17092 KB Output is correct
82 Correct 605 ms 17092 KB Output is correct
83 Correct 591 ms 17092 KB Output is correct
84 Correct 624 ms 17092 KB Output is correct
85 Correct 600 ms 17092 KB Output is correct
86 Correct 581 ms 17088 KB Output is correct
87 Correct 599 ms 16964 KB Output is correct
88 Correct 603 ms 17088 KB Output is correct
89 Correct 647 ms 17080 KB Output is correct
90 Correct 605 ms 17088 KB Output is correct
91 Correct 590 ms 17092 KB Output is correct
92 Correct 585 ms 17088 KB Output is correct
93 Correct 584 ms 17092 KB Output is correct
94 Correct 591 ms 17092 KB Output is correct
95 Correct 600 ms 17092 KB Output is correct
96 Correct 576 ms 17092 KB Output is correct
97 Correct 592 ms 17092 KB Output is correct
98 Correct 603 ms 17080 KB Output is correct
99 Correct 599 ms 17088 KB Output is correct
100 Correct 529 ms 17088 KB Output is correct
101 Correct 514 ms 17344 KB Output is correct
102 Correct 557 ms 16828 KB Output is correct
103 Correct 512 ms 17092 KB Output is correct
104 Correct 522 ms 17092 KB Output is correct
105 Correct 547 ms 16828 KB Output is correct
106 Correct 534 ms 16824 KB Output is correct
107 Correct 520 ms 17088 KB Output is correct
108 Correct 526 ms 17088 KB Output is correct
109 Correct 504 ms 17084 KB Output is correct
110 Correct 552 ms 17092 KB Output is correct
111 Correct 553 ms 17012 KB Output is correct
112 Correct 583 ms 17088 KB Output is correct
113 Correct 562 ms 16836 KB Output is correct
114 Correct 560 ms 17088 KB Output is correct
115 Correct 565 ms 16836 KB Output is correct
116 Correct 557 ms 17092 KB Output is correct
117 Correct 556 ms 17088 KB Output is correct
118 Correct 575 ms 17092 KB Output is correct
119 Correct 550 ms 17088 KB Output is correct
120 Correct 0 ms 348 KB Output is correct
121 Correct 0 ms 348 KB Output is correct
122 Correct 659 ms 17092 KB Output is correct
123 Correct 597 ms 17080 KB Output is correct
124 Correct 605 ms 17088 KB Output is correct
125 Correct 618 ms 17092 KB Output is correct
126 Correct 618 ms 17012 KB Output is correct
127 Correct 598 ms 17088 KB Output is correct
128 Correct 593 ms 17080 KB Output is correct
129 Correct 637 ms 17000 KB Output is correct
130 Correct 634 ms 17052 KB Output is correct
131 Correct 643 ms 17008 KB Output is correct
132 Correct 664 ms 17072 KB Output is correct
133 Correct 583 ms 17084 KB Output is correct