Submission #228167

# Submission time Handle Problem Language Result Execution time Memory
228167 2020-04-30T05:43:48 Z qkxwsm Bulldozer (JOI17_bulldozer) C++14
100 / 100
1686 ms 47796 KB
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef array<array<ll, 2>, 2> dparr;

const int MAXN = 2053;

struct point
{
    int x, y, w;
};

int N;
point arr[MAXN];
bool mark[MAXN][MAXN];
vector<pair<pll, pii> > events;
dparr seg[2 * MAXN];
int pos[MAXN];
ll ans;

dparr comb(dparr lt, dparr rt)
{
    dparr res;
    res[0][0] = max(lt[0][1] + rt[1][0], max(lt[0][0], rt[0][0]));
    res[0][1] = max(lt[0][1] + rt[1][1], rt[0][1]);
    res[1][0] = max(lt[1][0], lt[1][1] + rt[1][0]);
    res[1][1] = lt[1][1] + rt[1][1];
    return res;
}
void build(int w, int L, int R)
{
    if (L == R)
    {
        FOR(i, 0, 2) FOR(j, 0, 2) seg[w][i][j] = arr[L].w;
        return;
    }
    int mid = (L + R) >> 1;
    build(w << 1, L, mid);
    build(w << 1 | 1, mid + 1, R);
    seg[w] = comb(seg[w << 1], seg[w << 1 | 1]);
}
void update(int w, int L, int R, int a, int v)
{
    if (L == R)
    {
        FOR(i, 0, 2) FOR(j, 0, 2) seg[w][i][j] = v;
        return;
    }
    int mid = (L + R) >> 1;
    if (a <= mid) update(w << 1, L, mid, a, v);
    else update(w << 1 | 1, mid + 1, R, a, v);
    seg[w] = comb(seg[w << 1], seg[w << 1 | 1]);
}

ll gcd(ll a, ll b)
{
    return (b == 0 ? a : gcd(b, a % b));
}
pll normalize(pll p)
{
    ll g = gcd(abs(p.fi), abs(p.se));
    p.fi /= g; p.se /= g;
    if (p.se < 0)
    {
        p.se = -p.se;
        p.fi = -p.fi;
    }
    if (p.se == 0 && p.fi < 0)
    {
        p.fi = -p.fi;
    }
    return p;
}
bool cmp1(point a, point b)
{
    if (a.y != b.y)
    {
        return a.y < b.y;
    }
    return a.x < b.x;
}
bool cmp2(pair<pll, pii> a, pair<pll, pii> b)
{
    if (a.fi.fi * b.fi.se != b.fi.fi * a.fi.se)
    {
        return a.fi.fi * b.fi.se > b.fi.fi * a.fi.se;
    }
    return a.se < b.se;
}

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N;
    FOR(i, 0, N)
    {
        cin >> arr[i].x >> arr[i].y >> arr[i].w;
        ckmax(ans, arr[i].w);
    }
    sort(arr, arr + N, cmp1);
    iota(pos, pos + N, 0);
    build(1, 0, N - 1);
    // FOR(i, 0, N)
    // {
    //     cerr << arr[i].x << ' ' << arr[i].y << ' ' << arr[i].w << endl;
    // }
    //consider the order of the points. rotate the line sideways.
    //then, at a given slope, some vectors of lines reverse order.
    events.reserve(N * (N - 1) / 2);
    FOR(i, 0, N)
    {
        vector<pair<pll, int> > ve;
        FOR(j, i + 1, N)
        {
            if (mark[i][j])
            {
                continue;
            }
            pll p = normalize({arr[j].x - arr[i].x, arr[j].y - arr[i].y});
            events.PB({p, {i, j}});
        }
    }
    build(1, 0, N - 1);
    ckmax(ans, seg[1][0][0]);
    sort(ALL(events), cmp2);
    // cerr << "alive\n";
    FOR(i, 0, SZ(events))
    {
        auto a = events[i];
        pii p = a.se;
        swap(pos[p.fi], pos[p.se]);
        // cerr << "it swaps " << p.fi << ' ' << p.se << endl;
        update(1, 0, N - 1, pos[p.fi], arr[p.fi].w);
        update(1, 0, N - 1, pos[p.se], arr[p.se].w);
        //you can take all of it.
        if (i == SZ(events) - 1 || events[i].fi != events[i + 1].fi)
        {
            // assert(i == SZ(events) - 1);
            ckmax(ans, seg[1][0][0]);
        }
        // cerr << "return " << seg[1][0][0] << endl;
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 7 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 7 ms 512 KB Output is correct
6 Correct 7 ms 512 KB Output is correct
7 Correct 7 ms 512 KB Output is correct
8 Correct 8 ms 512 KB Output is correct
9 Correct 7 ms 512 KB Output is correct
10 Correct 7 ms 512 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 7 ms 512 KB Output is correct
22 Correct 7 ms 512 KB Output is correct
23 Correct 7 ms 512 KB Output is correct
24 Correct 7 ms 512 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 7 ms 512 KB Output is correct
27 Correct 7 ms 512 KB Output is correct
28 Correct 7 ms 512 KB Output is correct
29 Correct 7 ms 512 KB Output is correct
30 Correct 7 ms 640 KB Output is correct
31 Correct 7 ms 640 KB Output is correct
32 Correct 7 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 7 ms 512 KB Output is correct
6 Correct 7 ms 512 KB Output is correct
7 Correct 7 ms 512 KB Output is correct
8 Correct 8 ms 512 KB Output is correct
9 Correct 7 ms 512 KB Output is correct
10 Correct 7 ms 512 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 7 ms 512 KB Output is correct
22 Correct 7 ms 512 KB Output is correct
23 Correct 7 ms 512 KB Output is correct
24 Correct 7 ms 512 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 7 ms 512 KB Output is correct
27 Correct 7 ms 512 KB Output is correct
28 Correct 7 ms 512 KB Output is correct
29 Correct 7 ms 512 KB Output is correct
30 Correct 7 ms 640 KB Output is correct
31 Correct 7 ms 640 KB Output is correct
32 Correct 7 ms 512 KB Output is correct
33 Correct 1635 ms 47480 KB Output is correct
34 Correct 1629 ms 47480 KB Output is correct
35 Correct 1652 ms 47488 KB Output is correct
36 Correct 1651 ms 47544 KB Output is correct
37 Correct 1636 ms 47608 KB Output is correct
38 Correct 1651 ms 47480 KB Output is correct
39 Correct 1683 ms 47480 KB Output is correct
40 Correct 1686 ms 47480 KB Output is correct
41 Correct 1649 ms 47608 KB Output is correct
42 Correct 1663 ms 47480 KB Output is correct
43 Correct 1590 ms 47480 KB Output is correct
44 Correct 1608 ms 47480 KB Output is correct
45 Correct 1645 ms 47608 KB Output is correct
46 Correct 1632 ms 47484 KB Output is correct
47 Correct 1622 ms 47584 KB Output is correct
48 Correct 1644 ms 47588 KB Output is correct
49 Correct 1598 ms 47480 KB Output is correct
50 Correct 1636 ms 47532 KB Output is correct
51 Correct 1611 ms 47452 KB Output is correct
52 Correct 1608 ms 47516 KB Output is correct
53 Correct 1598 ms 47480 KB Output is correct
54 Correct 1599 ms 47480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 7 ms 512 KB Output is correct
6 Correct 7 ms 512 KB Output is correct
7 Correct 7 ms 512 KB Output is correct
8 Correct 8 ms 512 KB Output is correct
9 Correct 7 ms 512 KB Output is correct
10 Correct 7 ms 512 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 7 ms 512 KB Output is correct
22 Correct 7 ms 512 KB Output is correct
23 Correct 7 ms 512 KB Output is correct
24 Correct 7 ms 512 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 7 ms 512 KB Output is correct
27 Correct 7 ms 512 KB Output is correct
28 Correct 7 ms 512 KB Output is correct
29 Correct 7 ms 512 KB Output is correct
30 Correct 7 ms 640 KB Output is correct
31 Correct 7 ms 640 KB Output is correct
32 Correct 7 ms 512 KB Output is correct
33 Correct 1635 ms 47480 KB Output is correct
34 Correct 1629 ms 47480 KB Output is correct
35 Correct 1652 ms 47488 KB Output is correct
36 Correct 1651 ms 47544 KB Output is correct
37 Correct 1636 ms 47608 KB Output is correct
38 Correct 1651 ms 47480 KB Output is correct
39 Correct 1683 ms 47480 KB Output is correct
40 Correct 1686 ms 47480 KB Output is correct
41 Correct 1649 ms 47608 KB Output is correct
42 Correct 1663 ms 47480 KB Output is correct
43 Correct 1590 ms 47480 KB Output is correct
44 Correct 1608 ms 47480 KB Output is correct
45 Correct 1645 ms 47608 KB Output is correct
46 Correct 1632 ms 47484 KB Output is correct
47 Correct 1622 ms 47584 KB Output is correct
48 Correct 1644 ms 47588 KB Output is correct
49 Correct 1598 ms 47480 KB Output is correct
50 Correct 1636 ms 47532 KB Output is correct
51 Correct 1611 ms 47452 KB Output is correct
52 Correct 1608 ms 47516 KB Output is correct
53 Correct 1598 ms 47480 KB Output is correct
54 Correct 1599 ms 47480 KB Output is correct
55 Correct 1653 ms 47480 KB Output is correct
56 Correct 1643 ms 47796 KB Output is correct
57 Correct 1626 ms 47480 KB Output is correct
58 Correct 1651 ms 47480 KB Output is correct
59 Correct 1637 ms 47536 KB Output is correct
60 Correct 1650 ms 47620 KB Output is correct
61 Correct 1667 ms 47480 KB Output is correct
62 Correct 1649 ms 47608 KB Output is correct
63 Correct 1638 ms 47584 KB Output is correct
64 Correct 1630 ms 47608 KB Output is correct
65 Correct 1638 ms 47736 KB Output is correct
66 Correct 1631 ms 47480 KB Output is correct
67 Correct 1641 ms 47480 KB Output is correct
68 Correct 1638 ms 47456 KB Output is correct
69 Correct 1634 ms 47608 KB Output is correct
70 Correct 1660 ms 47480 KB Output is correct
71 Correct 1646 ms 47568 KB Output is correct
72 Correct 1642 ms 47608 KB Output is correct
73 Correct 1653 ms 47544 KB Output is correct
74 Correct 1654 ms 47480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 7 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 7 ms 512 KB Output is correct
17 Correct 7 ms 512 KB Output is correct
18 Correct 7 ms 512 KB Output is correct
19 Correct 7 ms 512 KB Output is correct
20 Correct 7 ms 512 KB Output is correct
21 Correct 7 ms 512 KB Output is correct
22 Correct 7 ms 512 KB Output is correct
23 Correct 8 ms 512 KB Output is correct
24 Correct 7 ms 512 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 7 ms 512 KB Output is correct
37 Correct 7 ms 512 KB Output is correct
38 Correct 7 ms 512 KB Output is correct
39 Correct 7 ms 512 KB Output is correct
40 Correct 7 ms 512 KB Output is correct
41 Correct 7 ms 512 KB Output is correct
42 Correct 7 ms 512 KB Output is correct
43 Correct 7 ms 512 KB Output is correct
44 Correct 7 ms 512 KB Output is correct
45 Correct 7 ms 640 KB Output is correct
46 Correct 7 ms 640 KB Output is correct
47 Correct 7 ms 512 KB Output is correct
48 Correct 1635 ms 47480 KB Output is correct
49 Correct 1629 ms 47480 KB Output is correct
50 Correct 1652 ms 47488 KB Output is correct
51 Correct 1651 ms 47544 KB Output is correct
52 Correct 1636 ms 47608 KB Output is correct
53 Correct 1651 ms 47480 KB Output is correct
54 Correct 1683 ms 47480 KB Output is correct
55 Correct 1686 ms 47480 KB Output is correct
56 Correct 1649 ms 47608 KB Output is correct
57 Correct 1663 ms 47480 KB Output is correct
58 Correct 1590 ms 47480 KB Output is correct
59 Correct 1608 ms 47480 KB Output is correct
60 Correct 1645 ms 47608 KB Output is correct
61 Correct 1632 ms 47484 KB Output is correct
62 Correct 1622 ms 47584 KB Output is correct
63 Correct 1644 ms 47588 KB Output is correct
64 Correct 1598 ms 47480 KB Output is correct
65 Correct 1636 ms 47532 KB Output is correct
66 Correct 1611 ms 47452 KB Output is correct
67 Correct 1608 ms 47516 KB Output is correct
68 Correct 1598 ms 47480 KB Output is correct
69 Correct 1599 ms 47480 KB Output is correct
70 Correct 1653 ms 47480 KB Output is correct
71 Correct 1643 ms 47796 KB Output is correct
72 Correct 1626 ms 47480 KB Output is correct
73 Correct 1651 ms 47480 KB Output is correct
74 Correct 1637 ms 47536 KB Output is correct
75 Correct 1650 ms 47620 KB Output is correct
76 Correct 1667 ms 47480 KB Output is correct
77 Correct 1649 ms 47608 KB Output is correct
78 Correct 1638 ms 47584 KB Output is correct
79 Correct 1630 ms 47608 KB Output is correct
80 Correct 1638 ms 47736 KB Output is correct
81 Correct 1631 ms 47480 KB Output is correct
82 Correct 1641 ms 47480 KB Output is correct
83 Correct 1638 ms 47456 KB Output is correct
84 Correct 1634 ms 47608 KB Output is correct
85 Correct 1660 ms 47480 KB Output is correct
86 Correct 1646 ms 47568 KB Output is correct
87 Correct 1642 ms 47608 KB Output is correct
88 Correct 1653 ms 47544 KB Output is correct
89 Correct 1654 ms 47480 KB Output is correct
90 Correct 1659 ms 47480 KB Output is correct
91 Correct 1649 ms 47608 KB Output is correct
92 Correct 1635 ms 47480 KB Output is correct
93 Correct 1644 ms 47480 KB Output is correct
94 Correct 1631 ms 47480 KB Output is correct
95 Correct 1632 ms 47608 KB Output is correct
96 Correct 1664 ms 47480 KB Output is correct
97 Correct 1658 ms 47608 KB Output is correct
98 Correct 1686 ms 47480 KB Output is correct
99 Correct 1639 ms 47480 KB Output is correct
100 Correct 1393 ms 47480 KB Output is correct
101 Correct 1439 ms 47480 KB Output is correct
102 Correct 1407 ms 47480 KB Output is correct
103 Correct 1378 ms 47480 KB Output is correct
104 Correct 1442 ms 47484 KB Output is correct
105 Correct 1426 ms 47480 KB Output is correct
106 Correct 1443 ms 47480 KB Output is correct
107 Correct 1433 ms 47480 KB Output is correct
108 Correct 1464 ms 47480 KB Output is correct
109 Correct 1536 ms 47480 KB Output is correct
110 Correct 1565 ms 47456 KB Output is correct
111 Correct 1548 ms 47520 KB Output is correct
112 Correct 1563 ms 47456 KB Output is correct
113 Correct 1543 ms 47460 KB Output is correct
114 Correct 1535 ms 47464 KB Output is correct
115 Correct 1544 ms 47480 KB Output is correct
116 Correct 1517 ms 47480 KB Output is correct
117 Correct 1510 ms 47544 KB Output is correct
118 Correct 1494 ms 47480 KB Output is correct
119 Correct 1491 ms 47480 KB Output is correct
120 Correct 5 ms 384 KB Output is correct
121 Correct 4 ms 384 KB Output is correct
122 Correct 1504 ms 47480 KB Output is correct
123 Correct 1513 ms 47480 KB Output is correct
124 Correct 1499 ms 47480 KB Output is correct
125 Correct 1522 ms 47480 KB Output is correct
126 Correct 1515 ms 47480 KB Output is correct
127 Correct 1516 ms 47480 KB Output is correct
128 Correct 1521 ms 47480 KB Output is correct
129 Correct 1527 ms 47480 KB Output is correct
130 Correct 1511 ms 47612 KB Output is correct
131 Correct 1524 ms 47480 KB Output is correct
132 Correct 1526 ms 47584 KB Output is correct
133 Correct 1529 ms 47608 KB Output is correct