Submission #93197

# Submission time Handle Problem Language Result Execution time Memory
93197 2019-01-07T07:44:59 Z Alexa2001 Bulldozer (JOI17_bulldozer) C++17
100 / 100
768 ms 33612 KB
#include <bits/stdc++.h>
#define left_son (node<<1)
#define right_son ((node<<1)|1)
#define mid ((st+dr)>>1)

using namespace std;

const int Nmax = 2005;
typedef long long ll;

ll ans = 0;
int n, i, j, where[Nmax], ord[Nmax];


class SegTree
{
    ll best[Nmax<<2], pref[Nmax<<2], suff[Nmax<<2], s[Nmax<<2];
public:
    void update(int node, int st, int dr, int pos, int val)
    {
        if(st== dr)
        {
            best[node] = pref[node] = suff[node] = max(0, val);
            s[node] = val;
            return;
        }

        if(pos <= mid) update(left_son, st, mid, pos, val);
            else update(right_son, mid+1, dr, pos, val);

        s[node] = s[left_son] + s[right_son];
        pref[node] = max(pref[left_son], s[left_son] + pref[right_son]);
        suff[node] = max(suff[right_son], s[right_son] + suff[left_son]);

        best[node] = max(best[left_son], best[right_son]);
        best[node] = max(best[node], suff[left_son] + pref[right_son]);
    }

    ll query()
    {
        return best[1];
    }
} aint;


struct point
{
    int x, y, p;
    bool operator < (const point &other) const
    {
        if(x == other.x) return y > other.y;
        return x > other.x;
    }
};
point a[Nmax];

struct intr
{
    int x, y, id1, id2;
    bool operator < (const intr &other) const
    {
        if((ll) x * other.y == (ll) y * other.x) return (make_pair(id1, id2) < make_pair(other.id1, other.id2));
        return (ll) x * other.y < (ll) y * other.x;
    }

    bool operator == (const intr &other) const
    {
        return (ll) x * other.y == (ll) y * other.x;
    }
};
vector<intr> intersect;

void apply(intr A)
{
    int p1 = where[A.id1], p2 = where[A.id2];
    assert(p1 + 1 == p2);

    aint.update(1, 1, n, p2, a[A.id1].p);
    aint.update(1, 1, n, p1, a[A.id2].p);

    swap(where[A.id1], where[A.id2]);
    swap(ord[p1], ord[p2]);
}

ll eval()
{
    return aint.query();
}

int main()
{
 //   freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> n;
    for(i=1; i<=n; ++i) cin >> a[i].x >> a[i].y >> a[i].p;

    sort(a+1, a+n+1);

    for(i=1; i<=n; ++i) ord[i] = i, where[i] = i;

    for(i=1; i<=n; ++i) aint.update(1, 1, n, i, a[i].p);
    ans = eval();

    for(i=1; i<=n; ++i)
        for(j=i+1; j<=n; ++j)
            if(a[i].x != a[j].x)
                intersect.push_back({a[i].y - a[j].y, a[i].x - a[j].x, i, j});
    sort(intersect.begin(), intersect.end());

    for(i=0; i<intersect.size(); ++i)
    {
        j = i;
        while(j<intersect.size() && intersect[i] == intersect[j])
            apply(intersect[j++]);
        i = j - 1;

        ans = max(ans, eval());
    }

    cout << ans << '\n';
    return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:111:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0; i<intersect.size(); ++i)
              ~^~~~~~~~~~~~~~~~~
bulldozer.cpp:114:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(j<intersect.size() && intersect[i] == intersect[j])
               ~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 612 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 560 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 3 ms 640 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 3 ms 556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 560 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 3 ms 640 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 3 ms 556 KB Output is correct
33 Correct 708 ms 33428 KB Output is correct
34 Correct 701 ms 33472 KB Output is correct
35 Correct 679 ms 33484 KB Output is correct
36 Correct 687 ms 33464 KB Output is correct
37 Correct 678 ms 33448 KB Output is correct
38 Correct 688 ms 33512 KB Output is correct
39 Correct 693 ms 33444 KB Output is correct
40 Correct 683 ms 33592 KB Output is correct
41 Correct 688 ms 33488 KB Output is correct
42 Correct 748 ms 33472 KB Output is correct
43 Correct 747 ms 33488 KB Output is correct
44 Correct 700 ms 33516 KB Output is correct
45 Correct 664 ms 33472 KB Output is correct
46 Correct 674 ms 33468 KB Output is correct
47 Correct 679 ms 33476 KB Output is correct
48 Correct 694 ms 33612 KB Output is correct
49 Correct 693 ms 33472 KB Output is correct
50 Correct 694 ms 33472 KB Output is correct
51 Correct 701 ms 33472 KB Output is correct
52 Correct 719 ms 33472 KB Output is correct
53 Correct 713 ms 33456 KB Output is correct
54 Correct 695 ms 33476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 560 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 3 ms 640 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 3 ms 556 KB Output is correct
33 Correct 708 ms 33428 KB Output is correct
34 Correct 701 ms 33472 KB Output is correct
35 Correct 679 ms 33484 KB Output is correct
36 Correct 687 ms 33464 KB Output is correct
37 Correct 678 ms 33448 KB Output is correct
38 Correct 688 ms 33512 KB Output is correct
39 Correct 693 ms 33444 KB Output is correct
40 Correct 683 ms 33592 KB Output is correct
41 Correct 688 ms 33488 KB Output is correct
42 Correct 748 ms 33472 KB Output is correct
43 Correct 747 ms 33488 KB Output is correct
44 Correct 700 ms 33516 KB Output is correct
45 Correct 664 ms 33472 KB Output is correct
46 Correct 674 ms 33468 KB Output is correct
47 Correct 679 ms 33476 KB Output is correct
48 Correct 694 ms 33612 KB Output is correct
49 Correct 693 ms 33472 KB Output is correct
50 Correct 694 ms 33472 KB Output is correct
51 Correct 701 ms 33472 KB Output is correct
52 Correct 719 ms 33472 KB Output is correct
53 Correct 713 ms 33456 KB Output is correct
54 Correct 695 ms 33476 KB Output is correct
55 Correct 702 ms 33484 KB Output is correct
56 Correct 700 ms 33472 KB Output is correct
57 Correct 715 ms 33488 KB Output is correct
58 Correct 696 ms 33472 KB Output is correct
59 Correct 669 ms 33496 KB Output is correct
60 Correct 674 ms 33472 KB Output is correct
61 Correct 697 ms 33472 KB Output is correct
62 Correct 727 ms 33532 KB Output is correct
63 Correct 730 ms 33472 KB Output is correct
64 Correct 676 ms 33496 KB Output is correct
65 Correct 710 ms 33488 KB Output is correct
66 Correct 714 ms 33472 KB Output is correct
67 Correct 710 ms 33472 KB Output is correct
68 Correct 714 ms 33472 KB Output is correct
69 Correct 673 ms 33488 KB Output is correct
70 Correct 695 ms 33472 KB Output is correct
71 Correct 685 ms 33492 KB Output is correct
72 Correct 696 ms 33472 KB Output is correct
73 Correct 687 ms 33488 KB Output is correct
74 Correct 688 ms 33472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 612 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 560 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 560 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 3 ms 640 KB Output is correct
37 Correct 3 ms 640 KB Output is correct
38 Correct 3 ms 640 KB Output is correct
39 Correct 4 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 4 ms 640 KB Output is correct
45 Correct 3 ms 640 KB Output is correct
46 Correct 3 ms 640 KB Output is correct
47 Correct 3 ms 556 KB Output is correct
48 Correct 708 ms 33428 KB Output is correct
49 Correct 701 ms 33472 KB Output is correct
50 Correct 679 ms 33484 KB Output is correct
51 Correct 687 ms 33464 KB Output is correct
52 Correct 678 ms 33448 KB Output is correct
53 Correct 688 ms 33512 KB Output is correct
54 Correct 693 ms 33444 KB Output is correct
55 Correct 683 ms 33592 KB Output is correct
56 Correct 688 ms 33488 KB Output is correct
57 Correct 748 ms 33472 KB Output is correct
58 Correct 747 ms 33488 KB Output is correct
59 Correct 700 ms 33516 KB Output is correct
60 Correct 664 ms 33472 KB Output is correct
61 Correct 674 ms 33468 KB Output is correct
62 Correct 679 ms 33476 KB Output is correct
63 Correct 694 ms 33612 KB Output is correct
64 Correct 693 ms 33472 KB Output is correct
65 Correct 694 ms 33472 KB Output is correct
66 Correct 701 ms 33472 KB Output is correct
67 Correct 719 ms 33472 KB Output is correct
68 Correct 713 ms 33456 KB Output is correct
69 Correct 695 ms 33476 KB Output is correct
70 Correct 702 ms 33484 KB Output is correct
71 Correct 700 ms 33472 KB Output is correct
72 Correct 715 ms 33488 KB Output is correct
73 Correct 696 ms 33472 KB Output is correct
74 Correct 669 ms 33496 KB Output is correct
75 Correct 674 ms 33472 KB Output is correct
76 Correct 697 ms 33472 KB Output is correct
77 Correct 727 ms 33532 KB Output is correct
78 Correct 730 ms 33472 KB Output is correct
79 Correct 676 ms 33496 KB Output is correct
80 Correct 710 ms 33488 KB Output is correct
81 Correct 714 ms 33472 KB Output is correct
82 Correct 710 ms 33472 KB Output is correct
83 Correct 714 ms 33472 KB Output is correct
84 Correct 673 ms 33488 KB Output is correct
85 Correct 695 ms 33472 KB Output is correct
86 Correct 685 ms 33492 KB Output is correct
87 Correct 696 ms 33472 KB Output is correct
88 Correct 687 ms 33488 KB Output is correct
89 Correct 688 ms 33472 KB Output is correct
90 Correct 680 ms 33472 KB Output is correct
91 Correct 697 ms 33536 KB Output is correct
92 Correct 686 ms 33472 KB Output is correct
93 Correct 677 ms 33472 KB Output is correct
94 Correct 676 ms 33472 KB Output is correct
95 Correct 693 ms 33472 KB Output is correct
96 Correct 680 ms 33536 KB Output is correct
97 Correct 693 ms 33472 KB Output is correct
98 Correct 676 ms 33496 KB Output is correct
99 Correct 684 ms 33472 KB Output is correct
100 Correct 309 ms 17132 KB Output is correct
101 Correct 327 ms 17124 KB Output is correct
102 Correct 299 ms 17132 KB Output is correct
103 Correct 297 ms 17116 KB Output is correct
104 Correct 302 ms 17108 KB Output is correct
105 Correct 460 ms 33488 KB Output is correct
106 Correct 424 ms 33472 KB Output is correct
107 Correct 422 ms 33472 KB Output is correct
108 Correct 431 ms 33492 KB Output is correct
109 Correct 445 ms 33476 KB Output is correct
110 Correct 628 ms 33488 KB Output is correct
111 Correct 643 ms 33472 KB Output is correct
112 Correct 626 ms 33488 KB Output is correct
113 Correct 637 ms 33472 KB Output is correct
114 Correct 642 ms 33476 KB Output is correct
115 Correct 658 ms 33488 KB Output is correct
116 Correct 626 ms 33448 KB Output is correct
117 Correct 677 ms 33472 KB Output is correct
118 Correct 621 ms 33476 KB Output is correct
119 Correct 626 ms 33472 KB Output is correct
120 Correct 2 ms 384 KB Output is correct
121 Correct 2 ms 384 KB Output is correct
122 Correct 684 ms 33472 KB Output is correct
123 Correct 686 ms 33472 KB Output is correct
124 Correct 672 ms 33492 KB Output is correct
125 Correct 670 ms 33528 KB Output is correct
126 Correct 669 ms 33472 KB Output is correct
127 Correct 681 ms 33600 KB Output is correct
128 Correct 678 ms 33492 KB Output is correct
129 Correct 678 ms 33472 KB Output is correct
130 Correct 691 ms 33476 KB Output is correct
131 Correct 675 ms 33472 KB Output is correct
132 Correct 768 ms 33472 KB Output is correct
133 Correct 667 ms 33472 KB Output is correct