답안 #539365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
539365 2022-03-18T18:53:01 Z jesus_coconut Bulldozer (JOI17_bulldozer) C++17
100 / 100
1721 ms 99224 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) begin(a), end(a)
#define pb push_back
#define eb emplace_back
using namespace std;

using ll = long long;

using cll = complex<long long>;
using pii = pair<int, int>;

int n;
vector<pair<cll, ll>> v;

ll cross(cll a, cll b) {
    return (conj(a) * b).imag();
}

ll ccw(cll a, cll b, cll c) {
    return cross(b - a, c - b);
}

bool sign(cll a) {
    return a.imag() > 0 || (a.imag() == 0 && a.real() > 0);
}

vector<pair<cll, pair<int, int>>> events;

struct Item {
    ll mxPref = 0, mxSuf = 0, mxSuma = 0, suma = 0;
};

struct SegTree {
    int static const N = (1 << 11);
    array<Item, 2 * N> val;

    Item merg(Item a, Item b) {
        Item ret;
        ret.mxPref = max(a.mxPref, a.suma + b.mxPref);
        ret.mxSuf = max(b.mxSuf, b.suma + a.mxSuf);
        ret.suma = a.suma + b.suma;
        ret.mxSuma = max({a.mxSuma, b.mxSuma, a.mxSuf + b.mxPref});
        return ret;
    }

    void upd(int p, ll elem, int ver, int lx, int rx) {
        if (rx - lx == 1) {
            val[ver].mxPref = val[ver].mxSuf = val[ver].mxSuma = val[ver].suma = elem;
            return;
        }
        int mid = (lx + rx) / 2;
        if (p < mid) upd(p, elem, ver * 2 + 1, lx, mid);
        else upd(p, elem, ver * 2 + 2, mid, rx);
        val[ver] = merg(val[ver * 2 + 1], val[ver * 2 + 2]);
    }

    void upd(int p, ll elem) { upd(p, elem, 0, 0, N); }

    ll query() { return val[0].mxSuma; }
};

int pos[2010];

void solve() {
    cin >> n;
    v.resize(n);
    for (auto &[p, val] : v) {
        ll a, b;
        cin >> a >> b >> val;
        p.real(a);
        p.imag(b);
    }
    sort(all(v), [](auto const &a, auto const &b) {
        return a.F.real() < b.F.real() || (a.F.real() == b.F.real() && a.F.imag() > b.F.imag());
    });
    SegTree st;
    for (int i = 0; i < n; ++i) {
        st.upd(i, v[i].S);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            events.eb((v[j].F - v[i].F) * cll(0, 1), pii{i, j});
            events.eb((v[j].F - v[i].F) * cll(0, -1), pii{j, i});
        }
    }
    sort(all(events), [&](auto const &a, auto const &b) {
        if (sign(a.F) != sign(b.F)) return sign(a.F) > sign(b.F);
        ll c = ccw(cll(0, 0), a.F, b.F);
        if (c == 0) return a.S < b.S;
        return c > 0;
    });
    ll res = st.query();
    iota(pos, pos + n + 10, 0);
    for (int i = 0; i < size(events); ++i) {
        auto p = events[i].S;
        st.upd(pos[p.F], v[p.S].S);
        st.upd(pos[p.S], v[p.F].S);
        swap(pos[p.F], pos[p.S]);
        if (i + 1 < size(events) && ccw(cll(0, 0), events[i].F, events[i+1].F) == 0) continue;
        res = max(res, st.query());
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();


    return 0;
}

Compilation message

bulldozer.cpp: In function 'void solve()':
bulldozer.cpp:96:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::complex<long long int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |     for (int i = 0; i < size(events); ++i) {
      |                     ~~^~~~~~~~~~~~~~
bulldozer.cpp:101:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::complex<long long int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         if (i + 1 < size(events) && ccw(cll(0, 0), events[i].F, events[i+1].F) == 0) continue;
      |             ~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 916 KB Output is correct
2 Correct 3 ms 916 KB Output is correct
3 Correct 3 ms 916 KB Output is correct
4 Correct 3 ms 896 KB Output is correct
5 Correct 3 ms 916 KB Output is correct
6 Correct 3 ms 916 KB Output is correct
7 Correct 3 ms 916 KB Output is correct
8 Correct 3 ms 916 KB Output is correct
9 Correct 3 ms 916 KB Output is correct
10 Correct 3 ms 896 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 452 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 916 KB Output is correct
2 Correct 4 ms 916 KB Output is correct
3 Correct 4 ms 916 KB Output is correct
4 Correct 4 ms 916 KB Output is correct
5 Correct 3 ms 916 KB Output is correct
6 Correct 3 ms 916 KB Output is correct
7 Correct 4 ms 916 KB Output is correct
8 Correct 3 ms 916 KB Output is correct
9 Correct 3 ms 916 KB Output is correct
10 Correct 4 ms 916 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 408 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 4 ms 916 KB Output is correct
22 Correct 4 ms 896 KB Output is correct
23 Correct 4 ms 916 KB Output is correct
24 Correct 4 ms 916 KB Output is correct
25 Correct 3 ms 916 KB Output is correct
26 Correct 3 ms 916 KB Output is correct
27 Correct 4 ms 916 KB Output is correct
28 Correct 3 ms 916 KB Output is correct
29 Correct 4 ms 916 KB Output is correct
30 Correct 4 ms 916 KB Output is correct
31 Correct 4 ms 916 KB Output is correct
32 Correct 3 ms 916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 916 KB Output is correct
2 Correct 4 ms 916 KB Output is correct
3 Correct 4 ms 916 KB Output is correct
4 Correct 4 ms 916 KB Output is correct
5 Correct 3 ms 916 KB Output is correct
6 Correct 3 ms 916 KB Output is correct
7 Correct 4 ms 916 KB Output is correct
8 Correct 3 ms 916 KB Output is correct
9 Correct 3 ms 916 KB Output is correct
10 Correct 4 ms 916 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 408 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 4 ms 916 KB Output is correct
22 Correct 4 ms 896 KB Output is correct
23 Correct 4 ms 916 KB Output is correct
24 Correct 4 ms 916 KB Output is correct
25 Correct 3 ms 916 KB Output is correct
26 Correct 3 ms 916 KB Output is correct
27 Correct 4 ms 916 KB Output is correct
28 Correct 3 ms 916 KB Output is correct
29 Correct 4 ms 916 KB Output is correct
30 Correct 4 ms 916 KB Output is correct
31 Correct 4 ms 916 KB Output is correct
32 Correct 3 ms 916 KB Output is correct
33 Correct 1597 ms 99156 KB Output is correct
34 Correct 1578 ms 99140 KB Output is correct
35 Correct 1589 ms 99180 KB Output is correct
36 Correct 1588 ms 99148 KB Output is correct
37 Correct 1594 ms 99224 KB Output is correct
38 Correct 1650 ms 99148 KB Output is correct
39 Correct 1626 ms 99132 KB Output is correct
40 Correct 1574 ms 99144 KB Output is correct
41 Correct 1580 ms 99108 KB Output is correct
42 Correct 1560 ms 99176 KB Output is correct
43 Correct 1619 ms 99108 KB Output is correct
44 Correct 1574 ms 99148 KB Output is correct
45 Correct 1570 ms 99144 KB Output is correct
46 Correct 1594 ms 99160 KB Output is correct
47 Correct 1580 ms 99084 KB Output is correct
48 Correct 1545 ms 99148 KB Output is correct
49 Correct 1581 ms 99100 KB Output is correct
50 Correct 1606 ms 99076 KB Output is correct
51 Correct 1543 ms 99148 KB Output is correct
52 Correct 1586 ms 99196 KB Output is correct
53 Correct 1629 ms 99132 KB Output is correct
54 Correct 1557 ms 99124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 916 KB Output is correct
2 Correct 4 ms 916 KB Output is correct
3 Correct 4 ms 916 KB Output is correct
4 Correct 4 ms 916 KB Output is correct
5 Correct 3 ms 916 KB Output is correct
6 Correct 3 ms 916 KB Output is correct
7 Correct 4 ms 916 KB Output is correct
8 Correct 3 ms 916 KB Output is correct
9 Correct 3 ms 916 KB Output is correct
10 Correct 4 ms 916 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 408 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 4 ms 916 KB Output is correct
22 Correct 4 ms 896 KB Output is correct
23 Correct 4 ms 916 KB Output is correct
24 Correct 4 ms 916 KB Output is correct
25 Correct 3 ms 916 KB Output is correct
26 Correct 3 ms 916 KB Output is correct
27 Correct 4 ms 916 KB Output is correct
28 Correct 3 ms 916 KB Output is correct
29 Correct 4 ms 916 KB Output is correct
30 Correct 4 ms 916 KB Output is correct
31 Correct 4 ms 916 KB Output is correct
32 Correct 3 ms 916 KB Output is correct
33 Correct 1597 ms 99156 KB Output is correct
34 Correct 1578 ms 99140 KB Output is correct
35 Correct 1589 ms 99180 KB Output is correct
36 Correct 1588 ms 99148 KB Output is correct
37 Correct 1594 ms 99224 KB Output is correct
38 Correct 1650 ms 99148 KB Output is correct
39 Correct 1626 ms 99132 KB Output is correct
40 Correct 1574 ms 99144 KB Output is correct
41 Correct 1580 ms 99108 KB Output is correct
42 Correct 1560 ms 99176 KB Output is correct
43 Correct 1619 ms 99108 KB Output is correct
44 Correct 1574 ms 99148 KB Output is correct
45 Correct 1570 ms 99144 KB Output is correct
46 Correct 1594 ms 99160 KB Output is correct
47 Correct 1580 ms 99084 KB Output is correct
48 Correct 1545 ms 99148 KB Output is correct
49 Correct 1581 ms 99100 KB Output is correct
50 Correct 1606 ms 99076 KB Output is correct
51 Correct 1543 ms 99148 KB Output is correct
52 Correct 1586 ms 99196 KB Output is correct
53 Correct 1629 ms 99132 KB Output is correct
54 Correct 1557 ms 99124 KB Output is correct
55 Correct 1539 ms 99140 KB Output is correct
56 Correct 1579 ms 99116 KB Output is correct
57 Correct 1555 ms 99148 KB Output is correct
58 Correct 1545 ms 99184 KB Output is correct
59 Correct 1622 ms 99088 KB Output is correct
60 Correct 1530 ms 99120 KB Output is correct
61 Correct 1560 ms 99092 KB Output is correct
62 Correct 1550 ms 99188 KB Output is correct
63 Correct 1602 ms 99124 KB Output is correct
64 Correct 1706 ms 99128 KB Output is correct
65 Correct 1694 ms 99140 KB Output is correct
66 Correct 1713 ms 99148 KB Output is correct
67 Correct 1721 ms 99116 KB Output is correct
68 Correct 1573 ms 99148 KB Output is correct
69 Correct 1592 ms 99176 KB Output is correct
70 Correct 1551 ms 99116 KB Output is correct
71 Correct 1607 ms 99180 KB Output is correct
72 Correct 1581 ms 99224 KB Output is correct
73 Correct 1654 ms 99148 KB Output is correct
74 Correct 1567 ms 99144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 916 KB Output is correct
2 Correct 3 ms 916 KB Output is correct
3 Correct 3 ms 916 KB Output is correct
4 Correct 3 ms 896 KB Output is correct
5 Correct 3 ms 916 KB Output is correct
6 Correct 3 ms 916 KB Output is correct
7 Correct 3 ms 916 KB Output is correct
8 Correct 3 ms 916 KB Output is correct
9 Correct 3 ms 916 KB Output is correct
10 Correct 3 ms 896 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 452 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 916 KB Output is correct
17 Correct 4 ms 916 KB Output is correct
18 Correct 4 ms 916 KB Output is correct
19 Correct 4 ms 916 KB Output is correct
20 Correct 3 ms 916 KB Output is correct
21 Correct 3 ms 916 KB Output is correct
22 Correct 4 ms 916 KB Output is correct
23 Correct 3 ms 916 KB Output is correct
24 Correct 3 ms 916 KB Output is correct
25 Correct 4 ms 916 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 408 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 4 ms 916 KB Output is correct
37 Correct 4 ms 896 KB Output is correct
38 Correct 4 ms 916 KB Output is correct
39 Correct 4 ms 916 KB Output is correct
40 Correct 3 ms 916 KB Output is correct
41 Correct 3 ms 916 KB Output is correct
42 Correct 4 ms 916 KB Output is correct
43 Correct 3 ms 916 KB Output is correct
44 Correct 4 ms 916 KB Output is correct
45 Correct 4 ms 916 KB Output is correct
46 Correct 4 ms 916 KB Output is correct
47 Correct 3 ms 916 KB Output is correct
48 Correct 1597 ms 99156 KB Output is correct
49 Correct 1578 ms 99140 KB Output is correct
50 Correct 1589 ms 99180 KB Output is correct
51 Correct 1588 ms 99148 KB Output is correct
52 Correct 1594 ms 99224 KB Output is correct
53 Correct 1650 ms 99148 KB Output is correct
54 Correct 1626 ms 99132 KB Output is correct
55 Correct 1574 ms 99144 KB Output is correct
56 Correct 1580 ms 99108 KB Output is correct
57 Correct 1560 ms 99176 KB Output is correct
58 Correct 1619 ms 99108 KB Output is correct
59 Correct 1574 ms 99148 KB Output is correct
60 Correct 1570 ms 99144 KB Output is correct
61 Correct 1594 ms 99160 KB Output is correct
62 Correct 1580 ms 99084 KB Output is correct
63 Correct 1545 ms 99148 KB Output is correct
64 Correct 1581 ms 99100 KB Output is correct
65 Correct 1606 ms 99076 KB Output is correct
66 Correct 1543 ms 99148 KB Output is correct
67 Correct 1586 ms 99196 KB Output is correct
68 Correct 1629 ms 99132 KB Output is correct
69 Correct 1557 ms 99124 KB Output is correct
70 Correct 1539 ms 99140 KB Output is correct
71 Correct 1579 ms 99116 KB Output is correct
72 Correct 1555 ms 99148 KB Output is correct
73 Correct 1545 ms 99184 KB Output is correct
74 Correct 1622 ms 99088 KB Output is correct
75 Correct 1530 ms 99120 KB Output is correct
76 Correct 1560 ms 99092 KB Output is correct
77 Correct 1550 ms 99188 KB Output is correct
78 Correct 1602 ms 99124 KB Output is correct
79 Correct 1706 ms 99128 KB Output is correct
80 Correct 1694 ms 99140 KB Output is correct
81 Correct 1713 ms 99148 KB Output is correct
82 Correct 1721 ms 99116 KB Output is correct
83 Correct 1573 ms 99148 KB Output is correct
84 Correct 1592 ms 99176 KB Output is correct
85 Correct 1551 ms 99116 KB Output is correct
86 Correct 1607 ms 99180 KB Output is correct
87 Correct 1581 ms 99224 KB Output is correct
88 Correct 1654 ms 99148 KB Output is correct
89 Correct 1567 ms 99144 KB Output is correct
90 Correct 1576 ms 99108 KB Output is correct
91 Correct 1578 ms 99104 KB Output is correct
92 Correct 1551 ms 99148 KB Output is correct
93 Correct 1614 ms 99220 KB Output is correct
94 Correct 1558 ms 99068 KB Output is correct
95 Correct 1577 ms 99112 KB Output is correct
96 Correct 1591 ms 99080 KB Output is correct
97 Correct 1608 ms 99080 KB Output is correct
98 Correct 1613 ms 99100 KB Output is correct
99 Correct 1715 ms 99064 KB Output is correct
100 Correct 1451 ms 99144 KB Output is correct
101 Correct 1426 ms 99128 KB Output is correct
102 Correct 1504 ms 99128 KB Output is correct
103 Correct 1372 ms 99140 KB Output is correct
104 Correct 1358 ms 99128 KB Output is correct
105 Correct 1368 ms 99148 KB Output is correct
106 Correct 1387 ms 99148 KB Output is correct
107 Correct 1386 ms 99156 KB Output is correct
108 Correct 1376 ms 99048 KB Output is correct
109 Correct 1360 ms 99124 KB Output is correct
110 Correct 1480 ms 99116 KB Output is correct
111 Correct 1382 ms 99164 KB Output is correct
112 Correct 1471 ms 99048 KB Output is correct
113 Correct 1409 ms 99144 KB Output is correct
114 Correct 1500 ms 99148 KB Output is correct
115 Correct 1429 ms 99052 KB Output is correct
116 Correct 1434 ms 99124 KB Output is correct
117 Correct 1462 ms 99056 KB Output is correct
118 Correct 1417 ms 99076 KB Output is correct
119 Correct 1431 ms 99148 KB Output is correct
120 Correct 1 ms 340 KB Output is correct
121 Correct 1 ms 340 KB Output is correct
122 Correct 1605 ms 99116 KB Output is correct
123 Correct 1603 ms 99156 KB Output is correct
124 Correct 1573 ms 99148 KB Output is correct
125 Correct 1569 ms 99104 KB Output is correct
126 Correct 1573 ms 99092 KB Output is correct
127 Correct 1570 ms 99124 KB Output is correct
128 Correct 1556 ms 99172 KB Output is correct
129 Correct 1599 ms 99180 KB Output is correct
130 Correct 1552 ms 99164 KB Output is correct
131 Correct 1512 ms 99184 KB Output is correct
132 Correct 1595 ms 99148 KB Output is correct
133 Correct 1542 ms 99148 KB Output is correct