Submission #897358

# Submission time Handle Problem Language Result Execution time Memory
897358 2024-01-03T02:14:36 Z box Bulldozer (JOI17_bulldozer) C++17
100 / 100
637 ms 63396 KB
#include <algorithm>
#include <array>
#include <iostream>
#include <numeric>
using namespace std;
    
#define ar array
#define ll long long
    
const int N = 2e3, N_ = 1 << 11;
    
ar<int, 2> norm(ar<int, 2> a) {
    int g = gcd(a[0], a[1]);
    a[0] /= g, a[1] /= g;
    if (a[1] < 0)
        a[0] *= -1, a[1] *= -1;
    return a;
}
bool comp(const ar<int, 2>& a, const ar<int, 2>& b) {
    return 1LL * a[0] * b[1] < 1LL * b[0] * a[1];
}
    
ar<ll, 4> operator+(const ar<ll, 4>& u, const ar<ll, 4>& v) {
    return {u[0] + v[0], max(u[1], u[0] + v[1]), max(v[2], u[2] + v[0]), max(u[2] + v[1], max(u[3], v[3]))};
}
    
int n_;
ar<ll, 4> t[N_ * 2];
    
void update(int i, int w) {
    t[i += n_] = {w, max(0, w), max(0, w), max(0, w)};
    while (i >>= 1)
        t[i] = t[i << 1 | 0] + t[i << 1 | 1];
}
    
int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    n_ = 1;
    while (n_ < n)
        n_ <<= 1;
    static ar<int, 3> p[N];
    for (int i = 0; i < n; i++) {
        auto &[x, y, w] = p[i];
        cin >> x >> y >> w;
    }
    sort(p, p + n);
    static pair<ar<int, 2>, ar<int, 2>> e[N * (N - 1) / 2];
    int m = 0;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            if (p[i][0] != p[j][0])
                e[m++] = make_pair(norm({p[j][1] - p[i][1], p[j][0] - p[i][0]}), ar<int, 2>{i, j});
    stable_sort(e, e + m, [&](const pair<ar<int, 2>, ar<int, 2>>& a, const pair<ar<int, 2>, ar<int, 2>>& b) {
        return comp(a.first, b.first);
    });
    static int o[N];
    for (int i = 0; i < n; i++) {
        update(i, p[i][2]);
        o[i] = i;
    }
    ll ans = t[1][3];
    for (int h = 0; h < m; h++) {
        auto [s, ij] = e[h];
        auto [i, j] = ij;
        swap(o[i], o[j]);
        update(o[i], p[i][2]), update(o[j], p[j][2]);
        if (h == m - 1 || s != e[h + 1].first)
            ans = max(ans, t[1][3]);
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2516 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2512 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 464 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 2 ms 2648 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 2 ms 2648 KB Output is correct
11 Correct 1 ms 344 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 348 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 348 KB Output is correct
19 Correct 0 ms 464 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 1 ms 2520 KB Output is correct
27 Correct 2 ms 2652 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2904 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 2 ms 2648 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 2 ms 2648 KB Output is correct
11 Correct 1 ms 344 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 348 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 348 KB Output is correct
19 Correct 0 ms 464 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 1 ms 2520 KB Output is correct
27 Correct 2 ms 2652 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2904 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 618 ms 63060 KB Output is correct
34 Correct 616 ms 63064 KB Output is correct
35 Correct 619 ms 63312 KB Output is correct
36 Correct 614 ms 63320 KB Output is correct
37 Correct 619 ms 63052 KB Output is correct
38 Correct 615 ms 63052 KB Output is correct
39 Correct 619 ms 63060 KB Output is correct
40 Correct 616 ms 63044 KB Output is correct
41 Correct 615 ms 63056 KB Output is correct
42 Correct 616 ms 63056 KB Output is correct
43 Correct 575 ms 63056 KB Output is correct
44 Correct 573 ms 63312 KB Output is correct
45 Correct 574 ms 63052 KB Output is correct
46 Correct 580 ms 63060 KB Output is correct
47 Correct 577 ms 63080 KB Output is correct
48 Correct 580 ms 63320 KB Output is correct
49 Correct 589 ms 63060 KB Output is correct
50 Correct 582 ms 63084 KB Output is correct
51 Correct 581 ms 63336 KB Output is correct
52 Correct 578 ms 63056 KB Output is correct
53 Correct 575 ms 63052 KB Output is correct
54 Correct 572 ms 63056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 2 ms 2648 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 2 ms 2648 KB Output is correct
11 Correct 1 ms 344 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 348 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 348 KB Output is correct
19 Correct 0 ms 464 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 1 ms 2520 KB Output is correct
27 Correct 2 ms 2652 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2904 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 618 ms 63060 KB Output is correct
34 Correct 616 ms 63064 KB Output is correct
35 Correct 619 ms 63312 KB Output is correct
36 Correct 614 ms 63320 KB Output is correct
37 Correct 619 ms 63052 KB Output is correct
38 Correct 615 ms 63052 KB Output is correct
39 Correct 619 ms 63060 KB Output is correct
40 Correct 616 ms 63044 KB Output is correct
41 Correct 615 ms 63056 KB Output is correct
42 Correct 616 ms 63056 KB Output is correct
43 Correct 575 ms 63056 KB Output is correct
44 Correct 573 ms 63312 KB Output is correct
45 Correct 574 ms 63052 KB Output is correct
46 Correct 580 ms 63060 KB Output is correct
47 Correct 577 ms 63080 KB Output is correct
48 Correct 580 ms 63320 KB Output is correct
49 Correct 589 ms 63060 KB Output is correct
50 Correct 582 ms 63084 KB Output is correct
51 Correct 581 ms 63336 KB Output is correct
52 Correct 578 ms 63056 KB Output is correct
53 Correct 575 ms 63052 KB Output is correct
54 Correct 572 ms 63056 KB Output is correct
55 Correct 613 ms 63308 KB Output is correct
56 Correct 621 ms 63044 KB Output is correct
57 Correct 612 ms 63052 KB Output is correct
58 Correct 613 ms 63060 KB Output is correct
59 Correct 613 ms 63048 KB Output is correct
60 Correct 613 ms 63312 KB Output is correct
61 Correct 637 ms 63092 KB Output is correct
62 Correct 621 ms 63292 KB Output is correct
63 Correct 637 ms 63048 KB Output is correct
64 Correct 633 ms 63088 KB Output is correct
65 Correct 636 ms 63088 KB Output is correct
66 Correct 623 ms 63068 KB Output is correct
67 Correct 616 ms 63060 KB Output is correct
68 Correct 613 ms 63064 KB Output is correct
69 Correct 624 ms 63088 KB Output is correct
70 Correct 616 ms 63052 KB Output is correct
71 Correct 610 ms 63060 KB Output is correct
72 Correct 611 ms 63300 KB Output is correct
73 Correct 615 ms 63076 KB Output is correct
74 Correct 617 ms 63080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2516 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2512 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 464 KB Output is correct
13 Correct 1 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 2648 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2648 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2648 KB Output is correct
26 Correct 1 ms 344 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 348 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 348 KB Output is correct
34 Correct 0 ms 464 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 2 ms 2652 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 1 ms 2520 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2904 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 2 ms 2652 KB Output is correct
48 Correct 618 ms 63060 KB Output is correct
49 Correct 616 ms 63064 KB Output is correct
50 Correct 619 ms 63312 KB Output is correct
51 Correct 614 ms 63320 KB Output is correct
52 Correct 619 ms 63052 KB Output is correct
53 Correct 615 ms 63052 KB Output is correct
54 Correct 619 ms 63060 KB Output is correct
55 Correct 616 ms 63044 KB Output is correct
56 Correct 615 ms 63056 KB Output is correct
57 Correct 616 ms 63056 KB Output is correct
58 Correct 575 ms 63056 KB Output is correct
59 Correct 573 ms 63312 KB Output is correct
60 Correct 574 ms 63052 KB Output is correct
61 Correct 580 ms 63060 KB Output is correct
62 Correct 577 ms 63080 KB Output is correct
63 Correct 580 ms 63320 KB Output is correct
64 Correct 589 ms 63060 KB Output is correct
65 Correct 582 ms 63084 KB Output is correct
66 Correct 581 ms 63336 KB Output is correct
67 Correct 578 ms 63056 KB Output is correct
68 Correct 575 ms 63052 KB Output is correct
69 Correct 572 ms 63056 KB Output is correct
70 Correct 613 ms 63308 KB Output is correct
71 Correct 621 ms 63044 KB Output is correct
72 Correct 612 ms 63052 KB Output is correct
73 Correct 613 ms 63060 KB Output is correct
74 Correct 613 ms 63048 KB Output is correct
75 Correct 613 ms 63312 KB Output is correct
76 Correct 637 ms 63092 KB Output is correct
77 Correct 621 ms 63292 KB Output is correct
78 Correct 637 ms 63048 KB Output is correct
79 Correct 633 ms 63088 KB Output is correct
80 Correct 636 ms 63088 KB Output is correct
81 Correct 623 ms 63068 KB Output is correct
82 Correct 616 ms 63060 KB Output is correct
83 Correct 613 ms 63064 KB Output is correct
84 Correct 624 ms 63088 KB Output is correct
85 Correct 616 ms 63052 KB Output is correct
86 Correct 610 ms 63060 KB Output is correct
87 Correct 611 ms 63300 KB Output is correct
88 Correct 615 ms 63076 KB Output is correct
89 Correct 617 ms 63080 KB Output is correct
90 Correct 615 ms 63064 KB Output is correct
91 Correct 616 ms 63052 KB Output is correct
92 Correct 614 ms 63128 KB Output is correct
93 Correct 618 ms 63088 KB Output is correct
94 Correct 613 ms 63052 KB Output is correct
95 Correct 614 ms 63060 KB Output is correct
96 Correct 614 ms 63316 KB Output is correct
97 Correct 619 ms 63092 KB Output is correct
98 Correct 615 ms 63052 KB Output is correct
99 Correct 612 ms 63080 KB Output is correct
100 Correct 196 ms 32596 KB Output is correct
101 Correct 188 ms 32592 KB Output is correct
102 Correct 191 ms 32596 KB Output is correct
103 Correct 192 ms 32592 KB Output is correct
104 Correct 194 ms 32604 KB Output is correct
105 Correct 271 ms 43860 KB Output is correct
106 Correct 271 ms 43856 KB Output is correct
107 Correct 264 ms 43852 KB Output is correct
108 Correct 265 ms 43860 KB Output is correct
109 Correct 274 ms 43836 KB Output is correct
110 Correct 415 ms 62036 KB Output is correct
111 Correct 419 ms 62048 KB Output is correct
112 Correct 416 ms 62036 KB Output is correct
113 Correct 415 ms 62032 KB Output is correct
114 Correct 429 ms 62024 KB Output is correct
115 Correct 423 ms 62008 KB Output is correct
116 Correct 430 ms 62012 KB Output is correct
117 Correct 427 ms 62044 KB Output is correct
118 Correct 432 ms 62048 KB Output is correct
119 Correct 426 ms 62008 KB Output is correct
120 Correct 0 ms 428 KB Output is correct
121 Correct 0 ms 348 KB Output is correct
122 Correct 561 ms 63092 KB Output is correct
123 Correct 522 ms 63056 KB Output is correct
124 Correct 531 ms 63052 KB Output is correct
125 Correct 523 ms 63060 KB Output is correct
126 Correct 527 ms 63060 KB Output is correct
127 Correct 521 ms 63060 KB Output is correct
128 Correct 524 ms 63396 KB Output is correct
129 Correct 526 ms 63052 KB Output is correct
130 Correct 517 ms 63060 KB Output is correct
131 Correct 528 ms 63080 KB Output is correct
132 Correct 526 ms 63060 KB Output is correct
133 Correct 526 ms 63060 KB Output is correct