Submission #146420

# Submission time Handle Problem Language Result Execution time Memory
146420 2019-08-24T00:13:10 Z osaaateiasavtnl Bulldozer (JOI17_bulldozer) C++14
100 / 100
1016 ms 66612 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define double long double
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
const int N = 2007, C = 1e9 + 7;
int n, ans = 0;
struct Point { 
    int x, y, c; 
    bool operator < (Point p) { return (y < p.y) || (y == p.y && x > p.x); }
} a[N];
namespace TREE {
struct Node {
    int l, r, sum, ans;
    Node (int x) {
        sum = x;
        l = r = ans = max(0ll, x);
    }
    Node () {}
};  
Node merge(Node l, Node r) {
    Node ans;
    ans.sum = l.sum + r.sum;
    ans.l = max(l.l, l.sum + r.l);
    ans.r = max(r.r, r.sum + l.r);
    ans.ans = max(max(l.ans, r.ans), l.r + r.l);
    return ans;
}
Node tree[N << 2];
void build(int v, int tl, int tr) {
    if (tl == tr) { tree[v] = Node(a[tl].c); return; }
    int tm = (tl + tr) >> 1;
    build(v * 2 + 1, tl, tm); build(v * 2 + 2, tm + 1, tr);
    tree[v] = merge(tree[v * 2 + 1], tree[v * 2 + 2]);
}
void upd(int v, int tl, int tr, int p, int x) {
    if (tl == tr) { tree[v] = Node(x); return; }
    int tm = (tl + tr) >> 1;
    if (p <= tm) upd(v * 2 + 1, tl, tm, p, x);
    else upd(v * 2 + 2, tm + 1, tr, p, x);
    tree[v] = merge(tree[v * 2 + 1], tree[v * 2 + 2]);
}
void build() { build(0, 0, n - 1); }
void upd(int p, int x) { upd(0, 0, n - 1, p, x); }  
void relax() { ans = max(ans, tree[0].ans); }
};
int cp(int x1, int y1, int x2, int y2) { return x1 * y2 - y1 * x2; }
struct Line {
    int x, y, i, j;
    bool operator < (Line l) { 
        int t = cp(x, y, l.x, l.y);
        return t > 0 || (t == 0 && i < l.i) || (t == 0 && i == l.i && j < l.j); 
    }
};  
int pos[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    using namespace TREE;
    cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i].x >> a[i].y >> a[i].c; a[i].x += C; a[i].y += C; }
    sort(a, a + n); build(); relax();
    vector <Line> l;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            l.app({a[j].x - a[i].x, a[j].y - a[i].y, i, j});
        }
    }
    for (int i = 0; i < n; ++i) pos[i] = i;
    sort(all(l));
    int ptr = 0;
    while (ptr < l.size()) {
        int t = ptr;
        while (ptr < l.size() && cp(l[t].x, l[t].y, l[ptr].x, l[ptr].y) == 0) {
            auto &e = l[ptr];
            upd(pos[e.i], a[e.j].c);
            upd(pos[e.j], a[e.i].c);
            swap(pos[e.i], pos[e.j]);
            ++ptr;
        }
        relax();
    }
    cout << ans << '\n';
}  

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:78:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (ptr < l.size()) {
            ~~~~^~~~~~~~~~
bulldozer.cpp:80:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (ptr < l.size() && cp(l[t].x, l[t].y, l[ptr].x, l[ptr].y) == 0) {
                ~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 760 KB Output is correct
2 Correct 4 ms 760 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 4 ms 760 KB Output is correct
7 Correct 4 ms 760 KB Output is correct
8 Correct 4 ms 760 KB Output is correct
9 Correct 4 ms 692 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 764 KB Output is correct
2 Correct 4 ms 760 KB Output is correct
3 Correct 4 ms 820 KB Output is correct
4 Correct 4 ms 760 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 4 ms 760 KB Output is correct
7 Correct 4 ms 756 KB Output is correct
8 Correct 4 ms 760 KB Output is correct
9 Correct 4 ms 760 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 4 ms 760 KB Output is correct
22 Correct 4 ms 760 KB Output is correct
23 Correct 4 ms 760 KB Output is correct
24 Correct 4 ms 760 KB Output is correct
25 Correct 10 ms 760 KB Output is correct
26 Correct 4 ms 760 KB Output is correct
27 Correct 5 ms 760 KB Output is correct
28 Correct 4 ms 760 KB Output is correct
29 Correct 4 ms 760 KB Output is correct
30 Correct 4 ms 760 KB Output is correct
31 Correct 4 ms 760 KB Output is correct
32 Correct 4 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 764 KB Output is correct
2 Correct 4 ms 760 KB Output is correct
3 Correct 4 ms 820 KB Output is correct
4 Correct 4 ms 760 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 4 ms 760 KB Output is correct
7 Correct 4 ms 756 KB Output is correct
8 Correct 4 ms 760 KB Output is correct
9 Correct 4 ms 760 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 4 ms 760 KB Output is correct
22 Correct 4 ms 760 KB Output is correct
23 Correct 4 ms 760 KB Output is correct
24 Correct 4 ms 760 KB Output is correct
25 Correct 10 ms 760 KB Output is correct
26 Correct 4 ms 760 KB Output is correct
27 Correct 5 ms 760 KB Output is correct
28 Correct 4 ms 760 KB Output is correct
29 Correct 4 ms 760 KB Output is correct
30 Correct 4 ms 760 KB Output is correct
31 Correct 4 ms 760 KB Output is correct
32 Correct 4 ms 764 KB Output is correct
33 Correct 979 ms 66432 KB Output is correct
34 Correct 1008 ms 66460 KB Output is correct
35 Correct 982 ms 66464 KB Output is correct
36 Correct 1004 ms 66336 KB Output is correct
37 Correct 978 ms 66408 KB Output is correct
38 Correct 970 ms 66460 KB Output is correct
39 Correct 970 ms 66460 KB Output is correct
40 Correct 971 ms 66332 KB Output is correct
41 Correct 964 ms 66460 KB Output is correct
42 Correct 971 ms 66460 KB Output is correct
43 Correct 971 ms 66432 KB Output is correct
44 Correct 962 ms 66460 KB Output is correct
45 Correct 963 ms 66332 KB Output is correct
46 Correct 959 ms 66432 KB Output is correct
47 Correct 969 ms 66332 KB Output is correct
48 Correct 978 ms 66332 KB Output is correct
49 Correct 963 ms 66336 KB Output is correct
50 Correct 962 ms 66332 KB Output is correct
51 Correct 977 ms 66332 KB Output is correct
52 Correct 971 ms 66460 KB Output is correct
53 Correct 971 ms 66332 KB Output is correct
54 Correct 985 ms 66460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 764 KB Output is correct
2 Correct 4 ms 760 KB Output is correct
3 Correct 4 ms 820 KB Output is correct
4 Correct 4 ms 760 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 4 ms 760 KB Output is correct
7 Correct 4 ms 756 KB Output is correct
8 Correct 4 ms 760 KB Output is correct
9 Correct 4 ms 760 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 4 ms 760 KB Output is correct
22 Correct 4 ms 760 KB Output is correct
23 Correct 4 ms 760 KB Output is correct
24 Correct 4 ms 760 KB Output is correct
25 Correct 10 ms 760 KB Output is correct
26 Correct 4 ms 760 KB Output is correct
27 Correct 5 ms 760 KB Output is correct
28 Correct 4 ms 760 KB Output is correct
29 Correct 4 ms 760 KB Output is correct
30 Correct 4 ms 760 KB Output is correct
31 Correct 4 ms 760 KB Output is correct
32 Correct 4 ms 764 KB Output is correct
33 Correct 979 ms 66432 KB Output is correct
34 Correct 1008 ms 66460 KB Output is correct
35 Correct 982 ms 66464 KB Output is correct
36 Correct 1004 ms 66336 KB Output is correct
37 Correct 978 ms 66408 KB Output is correct
38 Correct 970 ms 66460 KB Output is correct
39 Correct 970 ms 66460 KB Output is correct
40 Correct 971 ms 66332 KB Output is correct
41 Correct 964 ms 66460 KB Output is correct
42 Correct 971 ms 66460 KB Output is correct
43 Correct 971 ms 66432 KB Output is correct
44 Correct 962 ms 66460 KB Output is correct
45 Correct 963 ms 66332 KB Output is correct
46 Correct 959 ms 66432 KB Output is correct
47 Correct 969 ms 66332 KB Output is correct
48 Correct 978 ms 66332 KB Output is correct
49 Correct 963 ms 66336 KB Output is correct
50 Correct 962 ms 66332 KB Output is correct
51 Correct 977 ms 66332 KB Output is correct
52 Correct 971 ms 66460 KB Output is correct
53 Correct 971 ms 66332 KB Output is correct
54 Correct 985 ms 66460 KB Output is correct
55 Correct 976 ms 66380 KB Output is correct
56 Correct 969 ms 66460 KB Output is correct
57 Correct 979 ms 66460 KB Output is correct
58 Correct 982 ms 66396 KB Output is correct
59 Correct 979 ms 66328 KB Output is correct
60 Correct 976 ms 66332 KB Output is correct
61 Correct 999 ms 66416 KB Output is correct
62 Correct 967 ms 66460 KB Output is correct
63 Correct 970 ms 66460 KB Output is correct
64 Correct 975 ms 66384 KB Output is correct
65 Correct 982 ms 66460 KB Output is correct
66 Correct 975 ms 66460 KB Output is correct
67 Correct 967 ms 66464 KB Output is correct
68 Correct 983 ms 66332 KB Output is correct
69 Correct 976 ms 66416 KB Output is correct
70 Correct 981 ms 66332 KB Output is correct
71 Correct 969 ms 66464 KB Output is correct
72 Correct 982 ms 66464 KB Output is correct
73 Correct 1002 ms 66464 KB Output is correct
74 Correct 1016 ms 66396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 760 KB Output is correct
2 Correct 4 ms 760 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 4 ms 760 KB Output is correct
7 Correct 4 ms 760 KB Output is correct
8 Correct 4 ms 760 KB Output is correct
9 Correct 4 ms 692 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 4 ms 764 KB Output is correct
17 Correct 4 ms 760 KB Output is correct
18 Correct 4 ms 820 KB Output is correct
19 Correct 4 ms 760 KB Output is correct
20 Correct 4 ms 760 KB Output is correct
21 Correct 4 ms 760 KB Output is correct
22 Correct 4 ms 756 KB Output is correct
23 Correct 4 ms 760 KB Output is correct
24 Correct 4 ms 760 KB Output is correct
25 Correct 4 ms 760 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 4 ms 760 KB Output is correct
37 Correct 4 ms 760 KB Output is correct
38 Correct 4 ms 760 KB Output is correct
39 Correct 4 ms 760 KB Output is correct
40 Correct 10 ms 760 KB Output is correct
41 Correct 4 ms 760 KB Output is correct
42 Correct 5 ms 760 KB Output is correct
43 Correct 4 ms 760 KB Output is correct
44 Correct 4 ms 760 KB Output is correct
45 Correct 4 ms 760 KB Output is correct
46 Correct 4 ms 760 KB Output is correct
47 Correct 4 ms 764 KB Output is correct
48 Correct 979 ms 66432 KB Output is correct
49 Correct 1008 ms 66460 KB Output is correct
50 Correct 982 ms 66464 KB Output is correct
51 Correct 1004 ms 66336 KB Output is correct
52 Correct 978 ms 66408 KB Output is correct
53 Correct 970 ms 66460 KB Output is correct
54 Correct 970 ms 66460 KB Output is correct
55 Correct 971 ms 66332 KB Output is correct
56 Correct 964 ms 66460 KB Output is correct
57 Correct 971 ms 66460 KB Output is correct
58 Correct 971 ms 66432 KB Output is correct
59 Correct 962 ms 66460 KB Output is correct
60 Correct 963 ms 66332 KB Output is correct
61 Correct 959 ms 66432 KB Output is correct
62 Correct 969 ms 66332 KB Output is correct
63 Correct 978 ms 66332 KB Output is correct
64 Correct 963 ms 66336 KB Output is correct
65 Correct 962 ms 66332 KB Output is correct
66 Correct 977 ms 66332 KB Output is correct
67 Correct 971 ms 66460 KB Output is correct
68 Correct 971 ms 66332 KB Output is correct
69 Correct 985 ms 66460 KB Output is correct
70 Correct 976 ms 66380 KB Output is correct
71 Correct 969 ms 66460 KB Output is correct
72 Correct 979 ms 66460 KB Output is correct
73 Correct 982 ms 66396 KB Output is correct
74 Correct 979 ms 66328 KB Output is correct
75 Correct 976 ms 66332 KB Output is correct
76 Correct 999 ms 66416 KB Output is correct
77 Correct 967 ms 66460 KB Output is correct
78 Correct 970 ms 66460 KB Output is correct
79 Correct 975 ms 66384 KB Output is correct
80 Correct 982 ms 66460 KB Output is correct
81 Correct 975 ms 66460 KB Output is correct
82 Correct 967 ms 66464 KB Output is correct
83 Correct 983 ms 66332 KB Output is correct
84 Correct 976 ms 66416 KB Output is correct
85 Correct 981 ms 66332 KB Output is correct
86 Correct 969 ms 66464 KB Output is correct
87 Correct 982 ms 66464 KB Output is correct
88 Correct 1002 ms 66464 KB Output is correct
89 Correct 1016 ms 66396 KB Output is correct
90 Correct 972 ms 66416 KB Output is correct
91 Correct 966 ms 66460 KB Output is correct
92 Correct 977 ms 66468 KB Output is correct
93 Correct 980 ms 66456 KB Output is correct
94 Correct 982 ms 66460 KB Output is correct
95 Correct 1000 ms 66464 KB Output is correct
96 Correct 979 ms 66460 KB Output is correct
97 Correct 985 ms 66432 KB Output is correct
98 Correct 989 ms 66332 KB Output is correct
99 Correct 965 ms 66328 KB Output is correct
100 Correct 887 ms 66332 KB Output is correct
101 Correct 917 ms 66332 KB Output is correct
102 Correct 888 ms 66332 KB Output is correct
103 Correct 877 ms 66332 KB Output is correct
104 Correct 889 ms 66460 KB Output is correct
105 Correct 937 ms 66336 KB Output is correct
106 Correct 924 ms 66332 KB Output is correct
107 Correct 919 ms 66304 KB Output is correct
108 Correct 926 ms 66332 KB Output is correct
109 Correct 941 ms 66332 KB Output is correct
110 Correct 915 ms 66328 KB Output is correct
111 Correct 912 ms 66332 KB Output is correct
112 Correct 925 ms 66332 KB Output is correct
113 Correct 926 ms 66336 KB Output is correct
114 Correct 925 ms 66336 KB Output is correct
115 Correct 926 ms 66332 KB Output is correct
116 Correct 930 ms 66332 KB Output is correct
117 Correct 917 ms 66336 KB Output is correct
118 Correct 912 ms 66332 KB Output is correct
119 Correct 919 ms 66332 KB Output is correct
120 Correct 2 ms 376 KB Output is correct
121 Correct 2 ms 376 KB Output is correct
122 Correct 985 ms 66460 KB Output is correct
123 Correct 970 ms 66332 KB Output is correct
124 Correct 973 ms 66500 KB Output is correct
125 Correct 982 ms 66336 KB Output is correct
126 Correct 968 ms 66612 KB Output is correct
127 Correct 978 ms 66384 KB Output is correct
128 Correct 971 ms 66456 KB Output is correct
129 Correct 976 ms 66460 KB Output is correct
130 Correct 995 ms 66336 KB Output is correct
131 Correct 964 ms 66460 KB Output is correct
132 Correct 972 ms 66336 KB Output is correct
133 Correct 974 ms 66336 KB Output is correct