Submission #947934

# Submission time Handle Problem Language Result Execution time Memory
947934 2024-03-17T09:29:40 Z ha819ha Bulldozer (JOI17_bulldozer) C++17
100 / 100
558 ms 33568 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll, ll>;

#define x first
#define y second
#define all(v) (v).begin(), (v).end()

const int SZ = 2048;
struct Tree {
	long long L[SZ + SZ], R[SZ + SZ], S[SZ + SZ], M[SZ + SZ];
	void Put(int a, int b) {
		a += SZ;
		S[a] = b;
		L[a] = R[a] = M[a] = max(0, b);
		while (a != 1) {
			a >>= 1;
			S[a] = S[a + a] + S[a + a + 1];
			L[a] = max(L[a + a], S[a + a] + L[a + a + 1]);
			R[a] = max(R[a + a + 1], S[a + a + 1] + R[a + a]);
			M[a] = max(max(M[a + a], M[a + a + 1]), R[a + a] + L[a + a + 1]);
		}
	}
}T;

struct Point {
    int x,y,v;

    bool operator < (const Point& rhs) const {
        return pii(x, y) < pii(rhs.x, rhs.y);
    }
};

struct Line {
	int x, y, i, j;
	bool operator<(const Line &p)const {
		return (long long)y*p.x  != (long long)p.y*x ? (long long)y*p.x < (long long)p.y*x : i!=p.i?i<p.i:j<p.j;
	}
};

int main(void){
    cin.tie(0)->sync_with_stdio(0);

    int n; cin>>n;
    vector<Point> p(n);
    for(auto& [x,y,v]:p) cin>>x>>y>>v;

    sort(all(p));
    vector<int> pos(n);

    vector<Line> lines;

    for(int i=0;i<n;i++) {
        for(int j=i+1;j<n;j++) {
            int dx = p[j].x-p[i].x;
            int dy = p[j].y-p[i].y;
            if (dx < 0 || (dx == 0 && dy < 0))dx = -dx, dy = -dy;
            lines.push_back({dx,dy,i,j});
        }
    }
    sort(all(lines));

    for(int i=0;i<n;i++) {
        T.Put(i, p[i].v);
        pos[i]=i;
    }

    ll ans = T.M[1];

    int cnt = lines.size();
	for (int i = 0,j; i < cnt; i++) {
		for (j = i; j < cnt; j++) {
            if ((long long)lines[i].x*lines[j].y != (long long)lines[i].y*lines[j].x)break;
            int a = lines[j].i, b = lines[j].j;
            swap(pos[a], pos[b]);

            T.Put(pos[a], p[a].v);
            T.Put(pos[b], p[b].v);
        }
        ans = max(ans, T.M[1]);
        i=j-1;
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 712 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 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 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 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 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 360 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 712 KB Output is correct
22 Correct 2 ms 600 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 716 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 856 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 600 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 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 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 360 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 712 KB Output is correct
22 Correct 2 ms 600 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 716 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 856 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 600 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 525 ms 33472 KB Output is correct
34 Correct 524 ms 33476 KB Output is correct
35 Correct 525 ms 33476 KB Output is correct
36 Correct 522 ms 33468 KB Output is correct
37 Correct 531 ms 33476 KB Output is correct
38 Correct 518 ms 33476 KB Output is correct
39 Correct 522 ms 33376 KB Output is correct
40 Correct 526 ms 33468 KB Output is correct
41 Correct 529 ms 33464 KB Output is correct
42 Correct 526 ms 33412 KB Output is correct
43 Correct 528 ms 33468 KB Output is correct
44 Correct 518 ms 33464 KB Output is correct
45 Correct 519 ms 33356 KB Output is correct
46 Correct 529 ms 33348 KB Output is correct
47 Correct 516 ms 33468 KB Output is correct
48 Correct 517 ms 33468 KB Output is correct
49 Correct 526 ms 33464 KB Output is correct
50 Correct 529 ms 33468 KB Output is correct
51 Correct 522 ms 33372 KB Output is correct
52 Correct 520 ms 33456 KB Output is correct
53 Correct 516 ms 33472 KB Output is correct
54 Correct 519 ms 33568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 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 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 360 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 712 KB Output is correct
22 Correct 2 ms 600 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 716 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 856 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 600 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 525 ms 33472 KB Output is correct
34 Correct 524 ms 33476 KB Output is correct
35 Correct 525 ms 33476 KB Output is correct
36 Correct 522 ms 33468 KB Output is correct
37 Correct 531 ms 33476 KB Output is correct
38 Correct 518 ms 33476 KB Output is correct
39 Correct 522 ms 33376 KB Output is correct
40 Correct 526 ms 33468 KB Output is correct
41 Correct 529 ms 33464 KB Output is correct
42 Correct 526 ms 33412 KB Output is correct
43 Correct 528 ms 33468 KB Output is correct
44 Correct 518 ms 33464 KB Output is correct
45 Correct 519 ms 33356 KB Output is correct
46 Correct 529 ms 33348 KB Output is correct
47 Correct 516 ms 33468 KB Output is correct
48 Correct 517 ms 33468 KB Output is correct
49 Correct 526 ms 33464 KB Output is correct
50 Correct 529 ms 33468 KB Output is correct
51 Correct 522 ms 33372 KB Output is correct
52 Correct 520 ms 33456 KB Output is correct
53 Correct 516 ms 33472 KB Output is correct
54 Correct 519 ms 33568 KB Output is correct
55 Correct 529 ms 33472 KB Output is correct
56 Correct 527 ms 33388 KB Output is correct
57 Correct 522 ms 33476 KB Output is correct
58 Correct 526 ms 33464 KB Output is correct
59 Correct 527 ms 33468 KB Output is correct
60 Correct 535 ms 33328 KB Output is correct
61 Correct 536 ms 33464 KB Output is correct
62 Correct 525 ms 33472 KB Output is correct
63 Correct 533 ms 33476 KB Output is correct
64 Correct 558 ms 33464 KB Output is correct
65 Correct 522 ms 33456 KB Output is correct
66 Correct 541 ms 33360 KB Output is correct
67 Correct 516 ms 33476 KB Output is correct
68 Correct 520 ms 33456 KB Output is correct
69 Correct 522 ms 33492 KB Output is correct
70 Correct 530 ms 33424 KB Output is correct
71 Correct 523 ms 33460 KB Output is correct
72 Correct 522 ms 33468 KB Output is correct
73 Correct 526 ms 33500 KB Output is correct
74 Correct 533 ms 33484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 712 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 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 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 2 ms 760 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 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 0 ms 348 KB Output is correct
27 Correct 0 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 360 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 2 ms 712 KB Output is correct
37 Correct 2 ms 600 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 716 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 856 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 2 ms 604 KB Output is correct
46 Correct 2 ms 600 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 525 ms 33472 KB Output is correct
49 Correct 524 ms 33476 KB Output is correct
50 Correct 525 ms 33476 KB Output is correct
51 Correct 522 ms 33468 KB Output is correct
52 Correct 531 ms 33476 KB Output is correct
53 Correct 518 ms 33476 KB Output is correct
54 Correct 522 ms 33376 KB Output is correct
55 Correct 526 ms 33468 KB Output is correct
56 Correct 529 ms 33464 KB Output is correct
57 Correct 526 ms 33412 KB Output is correct
58 Correct 528 ms 33468 KB Output is correct
59 Correct 518 ms 33464 KB Output is correct
60 Correct 519 ms 33356 KB Output is correct
61 Correct 529 ms 33348 KB Output is correct
62 Correct 516 ms 33468 KB Output is correct
63 Correct 517 ms 33468 KB Output is correct
64 Correct 526 ms 33464 KB Output is correct
65 Correct 529 ms 33468 KB Output is correct
66 Correct 522 ms 33372 KB Output is correct
67 Correct 520 ms 33456 KB Output is correct
68 Correct 516 ms 33472 KB Output is correct
69 Correct 519 ms 33568 KB Output is correct
70 Correct 529 ms 33472 KB Output is correct
71 Correct 527 ms 33388 KB Output is correct
72 Correct 522 ms 33476 KB Output is correct
73 Correct 526 ms 33464 KB Output is correct
74 Correct 527 ms 33468 KB Output is correct
75 Correct 535 ms 33328 KB Output is correct
76 Correct 536 ms 33464 KB Output is correct
77 Correct 525 ms 33472 KB Output is correct
78 Correct 533 ms 33476 KB Output is correct
79 Correct 558 ms 33464 KB Output is correct
80 Correct 522 ms 33456 KB Output is correct
81 Correct 541 ms 33360 KB Output is correct
82 Correct 516 ms 33476 KB Output is correct
83 Correct 520 ms 33456 KB Output is correct
84 Correct 522 ms 33492 KB Output is correct
85 Correct 530 ms 33424 KB Output is correct
86 Correct 523 ms 33460 KB Output is correct
87 Correct 522 ms 33468 KB Output is correct
88 Correct 526 ms 33500 KB Output is correct
89 Correct 533 ms 33484 KB Output is correct
90 Correct 530 ms 33472 KB Output is correct
91 Correct 519 ms 33468 KB Output is correct
92 Correct 529 ms 33464 KB Output is correct
93 Correct 526 ms 33472 KB Output is correct
94 Correct 532 ms 33472 KB Output is correct
95 Correct 524 ms 33332 KB Output is correct
96 Correct 539 ms 33476 KB Output is correct
97 Correct 522 ms 33476 KB Output is correct
98 Correct 526 ms 33320 KB Output is correct
99 Correct 521 ms 33468 KB Output is correct
100 Correct 443 ms 33272 KB Output is correct
101 Correct 449 ms 33476 KB Output is correct
102 Correct 443 ms 33476 KB Output is correct
103 Correct 443 ms 33464 KB Output is correct
104 Correct 440 ms 33348 KB Output is correct
105 Correct 473 ms 33464 KB Output is correct
106 Correct 463 ms 33472 KB Output is correct
107 Correct 453 ms 33404 KB Output is correct
108 Correct 457 ms 33444 KB Output is correct
109 Correct 465 ms 33456 KB Output is correct
110 Correct 525 ms 33480 KB Output is correct
111 Correct 523 ms 33468 KB Output is correct
112 Correct 521 ms 33472 KB Output is correct
113 Correct 520 ms 33468 KB Output is correct
114 Correct 525 ms 33472 KB Output is correct
115 Correct 529 ms 33292 KB Output is correct
116 Correct 523 ms 33476 KB Output is correct
117 Correct 523 ms 33452 KB Output is correct
118 Correct 517 ms 33512 KB Output is correct
119 Correct 518 ms 33476 KB Output is correct
120 Correct 0 ms 344 KB Output is correct
121 Correct 0 ms 348 KB Output is correct
122 Correct 525 ms 33468 KB Output is correct
123 Correct 524 ms 33464 KB Output is correct
124 Correct 528 ms 33476 KB Output is correct
125 Correct 533 ms 33456 KB Output is correct
126 Correct 525 ms 33468 KB Output is correct
127 Correct 527 ms 33468 KB Output is correct
128 Correct 523 ms 33476 KB Output is correct
129 Correct 520 ms 33392 KB Output is correct
130 Correct 535 ms 33472 KB Output is correct
131 Correct 523 ms 33464 KB Output is correct
132 Correct 522 ms 33468 KB Output is correct
133 Correct 527 ms 33464 KB Output is correct