Submission #220625

# Submission time Handle Problem Language Result Execution time Memory
220625 2020-04-08T09:50:00 Z PeppaPig Bulldozer (JOI17_bulldozer) C++14
100 / 100
1006 ms 33740 KB
#include <bits/stdc++.h>

#define long long long
#define pii pair<long, long>
#define x first
#define y second

using namespace std;

const int N = 1 << 11;
const long INF = 1e18;

struct Point {
    int x, y, c;
    Point() {}
    Point(int x, int y, int c) : x(x), y(y), c(c) {}
    friend bool operator<(const Point &a, const Point &b) {
        return make_pair(pii(a.x, -a.y), a.c) < make_pair(pii(b.x, -b.y), b.c); 
    }
};

struct Line {
    int dx, dy, x, y;
    Line() {}
    Line(int dx, int dy, int x, int y) : dx(dx), dy(dy), x(x), y(y) {}
    friend bool operator<(const Line &a, const Line &b) {
        long d = 1ll * a.dy * b.dx - 1ll * b.dy * a.dx;
        if(d == 0) return pii(a.x, a.y) < pii(b.x, b.y);
        return d > 0;
    }
};

int n, pos[N];
vector<Point> point;
vector<Line> line;

struct item {
    long pre, suf, sum, ans;
    item() : pre(-INF), suf(-INF), sum(-INF), ans(-INF) {} 
    item(long x) : pre(x), suf(x), sum(x), ans(x) {}
    friend item operator+(const item &a, const item &b) {
        item ret;
        ret.pre = max(a.pre, a.sum + b.pre);
        ret.suf = max(b.suf, a.suf + b.sum);
        ret.sum = a.sum + b.sum;
        ret.ans = max({a.ans, b.ans, a.suf + b.pre});
        return ret;
    }
} t[N << 1];

void build(int p = 1, int l = 0, int r = n - 1) {
    if(l == r) return void(t[p] = item(point[l].c));
    int mid = (l + r) >> 1;
    build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);
    t[p] = t[p << 1] + t[p << 1 | 1];
}

void update(int x, int k, int p = 1, int l = 0, int r = n - 1) {
    if(l == r) return void(t[p] = item(k));
    int mid = (l + r) >> 1;
    if(x <= mid) update(x, k, p << 1, l, mid);
    else update(x, k, p << 1 | 1, mid + 1, r);
    t[p] = t[p << 1] + t[p << 1 | 1];
}

int main() {
    iota(pos, pos + N, 0);

    scanf("%d", &n);
    point.resize(n);
    for(int i = 0; i < n; i++) scanf("%d %d %d", &point[i].x, &point[i].y, &point[i].c);

    sort(point.begin(), point.end());
    for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) {
        if(point[i].x == point[j].x) continue;
        line.emplace_back(point[j].x - point[i].x, point[j].y - point[i].y, i, j);
    }
    sort(line.begin(), line.end());
    
    build();

    long ans = max(0ll, t[1].ans);
    for(int i = 0; i < line.size(); i++) {
        int a = line[i].x, b = line[i].y;

        update(pos[a], point[b].c), update(pos[b], point[a].c);
        swap(pos[a], pos[b]);

        if(i == line.size() - 1 || 1ll * line[i].dy * line[i + 1].dx != 1ll * line[i].dx * line[i + 1].dy)
            ans = max(ans, t[1].ans);
    }
    printf("%lld\n", ans);

    return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:83:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < line.size(); i++) {
                    ~~^~~~~~~~~~~~~
bulldozer.cpp:89:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i == line.size() - 1 || 1ll * line[i].dy * line[i + 1].dx != 1ll * line[i].dx * line[i + 1].dy)
            ~~^~~~~~~~~~~~~~~~~~
bulldozer.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
bulldozer.cpp:71:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 0; i < n; i++) scanf("%d %d %d", &point[i].x, &point[i].y, &point[i].c);
                                ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 4 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 4 ms 512 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 6 ms 640 KB Output is correct
23 Correct 6 ms 640 KB Output is correct
24 Correct 7 ms 640 KB Output is correct
25 Correct 6 ms 640 KB Output is correct
26 Correct 6 ms 640 KB Output is correct
27 Correct 6 ms 640 KB Output is correct
28 Correct 6 ms 640 KB Output is correct
29 Correct 6 ms 640 KB Output is correct
30 Correct 7 ms 640 KB Output is correct
31 Correct 6 ms 640 KB Output is correct
32 Correct 6 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 4 ms 512 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 6 ms 640 KB Output is correct
23 Correct 6 ms 640 KB Output is correct
24 Correct 7 ms 640 KB Output is correct
25 Correct 6 ms 640 KB Output is correct
26 Correct 6 ms 640 KB Output is correct
27 Correct 6 ms 640 KB Output is correct
28 Correct 6 ms 640 KB Output is correct
29 Correct 6 ms 640 KB Output is correct
30 Correct 7 ms 640 KB Output is correct
31 Correct 6 ms 640 KB Output is correct
32 Correct 6 ms 640 KB Output is correct
33 Correct 981 ms 33508 KB Output is correct
34 Correct 968 ms 33496 KB Output is correct
35 Correct 918 ms 33496 KB Output is correct
36 Correct 946 ms 33500 KB Output is correct
37 Correct 970 ms 33612 KB Output is correct
38 Correct 947 ms 33500 KB Output is correct
39 Correct 977 ms 33492 KB Output is correct
40 Correct 951 ms 33500 KB Output is correct
41 Correct 979 ms 33500 KB Output is correct
42 Correct 952 ms 33508 KB Output is correct
43 Correct 961 ms 33500 KB Output is correct
44 Correct 927 ms 33508 KB Output is correct
45 Correct 955 ms 33484 KB Output is correct
46 Correct 1006 ms 33508 KB Output is correct
47 Correct 928 ms 33500 KB Output is correct
48 Correct 931 ms 33468 KB Output is correct
49 Correct 924 ms 33500 KB Output is correct
50 Correct 961 ms 33628 KB Output is correct
51 Correct 959 ms 33612 KB Output is correct
52 Correct 976 ms 33500 KB Output is correct
53 Correct 957 ms 33508 KB Output is correct
54 Correct 930 ms 33580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 4 ms 512 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 6 ms 640 KB Output is correct
23 Correct 6 ms 640 KB Output is correct
24 Correct 7 ms 640 KB Output is correct
25 Correct 6 ms 640 KB Output is correct
26 Correct 6 ms 640 KB Output is correct
27 Correct 6 ms 640 KB Output is correct
28 Correct 6 ms 640 KB Output is correct
29 Correct 6 ms 640 KB Output is correct
30 Correct 7 ms 640 KB Output is correct
31 Correct 6 ms 640 KB Output is correct
32 Correct 6 ms 640 KB Output is correct
33 Correct 981 ms 33508 KB Output is correct
34 Correct 968 ms 33496 KB Output is correct
35 Correct 918 ms 33496 KB Output is correct
36 Correct 946 ms 33500 KB Output is correct
37 Correct 970 ms 33612 KB Output is correct
38 Correct 947 ms 33500 KB Output is correct
39 Correct 977 ms 33492 KB Output is correct
40 Correct 951 ms 33500 KB Output is correct
41 Correct 979 ms 33500 KB Output is correct
42 Correct 952 ms 33508 KB Output is correct
43 Correct 961 ms 33500 KB Output is correct
44 Correct 927 ms 33508 KB Output is correct
45 Correct 955 ms 33484 KB Output is correct
46 Correct 1006 ms 33508 KB Output is correct
47 Correct 928 ms 33500 KB Output is correct
48 Correct 931 ms 33468 KB Output is correct
49 Correct 924 ms 33500 KB Output is correct
50 Correct 961 ms 33628 KB Output is correct
51 Correct 959 ms 33612 KB Output is correct
52 Correct 976 ms 33500 KB Output is correct
53 Correct 957 ms 33508 KB Output is correct
54 Correct 930 ms 33580 KB Output is correct
55 Correct 950 ms 33500 KB Output is correct
56 Correct 943 ms 33500 KB Output is correct
57 Correct 963 ms 33500 KB Output is correct
58 Correct 954 ms 33484 KB Output is correct
59 Correct 967 ms 33508 KB Output is correct
60 Correct 940 ms 33488 KB Output is correct
61 Correct 937 ms 33500 KB Output is correct
62 Correct 987 ms 33508 KB Output is correct
63 Correct 934 ms 33500 KB Output is correct
64 Correct 976 ms 33508 KB Output is correct
65 Correct 939 ms 33496 KB Output is correct
66 Correct 948 ms 33500 KB Output is correct
67 Correct 955 ms 33508 KB Output is correct
68 Correct 981 ms 33508 KB Output is correct
69 Correct 952 ms 33508 KB Output is correct
70 Correct 943 ms 33508 KB Output is correct
71 Correct 942 ms 33500 KB Output is correct
72 Correct 971 ms 33496 KB Output is correct
73 Correct 955 ms 33488 KB Output is correct
74 Correct 943 ms 33504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 4 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 7 ms 640 KB Output is correct
19 Correct 6 ms 640 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 6 ms 640 KB Output is correct
23 Correct 6 ms 640 KB Output is correct
24 Correct 6 ms 640 KB Output is correct
25 Correct 6 ms 640 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 512 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 4 ms 512 KB Output is correct
36 Correct 6 ms 640 KB Output is correct
37 Correct 6 ms 640 KB Output is correct
38 Correct 6 ms 640 KB Output is correct
39 Correct 7 ms 640 KB Output is correct
40 Correct 6 ms 640 KB Output is correct
41 Correct 6 ms 640 KB Output is correct
42 Correct 6 ms 640 KB Output is correct
43 Correct 6 ms 640 KB Output is correct
44 Correct 6 ms 640 KB Output is correct
45 Correct 7 ms 640 KB Output is correct
46 Correct 6 ms 640 KB Output is correct
47 Correct 6 ms 640 KB Output is correct
48 Correct 981 ms 33508 KB Output is correct
49 Correct 968 ms 33496 KB Output is correct
50 Correct 918 ms 33496 KB Output is correct
51 Correct 946 ms 33500 KB Output is correct
52 Correct 970 ms 33612 KB Output is correct
53 Correct 947 ms 33500 KB Output is correct
54 Correct 977 ms 33492 KB Output is correct
55 Correct 951 ms 33500 KB Output is correct
56 Correct 979 ms 33500 KB Output is correct
57 Correct 952 ms 33508 KB Output is correct
58 Correct 961 ms 33500 KB Output is correct
59 Correct 927 ms 33508 KB Output is correct
60 Correct 955 ms 33484 KB Output is correct
61 Correct 1006 ms 33508 KB Output is correct
62 Correct 928 ms 33500 KB Output is correct
63 Correct 931 ms 33468 KB Output is correct
64 Correct 924 ms 33500 KB Output is correct
65 Correct 961 ms 33628 KB Output is correct
66 Correct 959 ms 33612 KB Output is correct
67 Correct 976 ms 33500 KB Output is correct
68 Correct 957 ms 33508 KB Output is correct
69 Correct 930 ms 33580 KB Output is correct
70 Correct 950 ms 33500 KB Output is correct
71 Correct 943 ms 33500 KB Output is correct
72 Correct 963 ms 33500 KB Output is correct
73 Correct 954 ms 33484 KB Output is correct
74 Correct 967 ms 33508 KB Output is correct
75 Correct 940 ms 33488 KB Output is correct
76 Correct 937 ms 33500 KB Output is correct
77 Correct 987 ms 33508 KB Output is correct
78 Correct 934 ms 33500 KB Output is correct
79 Correct 976 ms 33508 KB Output is correct
80 Correct 939 ms 33496 KB Output is correct
81 Correct 948 ms 33500 KB Output is correct
82 Correct 955 ms 33508 KB Output is correct
83 Correct 981 ms 33508 KB Output is correct
84 Correct 952 ms 33508 KB Output is correct
85 Correct 943 ms 33508 KB Output is correct
86 Correct 942 ms 33500 KB Output is correct
87 Correct 971 ms 33496 KB Output is correct
88 Correct 955 ms 33488 KB Output is correct
89 Correct 943 ms 33504 KB Output is correct
90 Correct 956 ms 33492 KB Output is correct
91 Correct 983 ms 33660 KB Output is correct
92 Correct 938 ms 33508 KB Output is correct
93 Correct 959 ms 33500 KB Output is correct
94 Correct 973 ms 33500 KB Output is correct
95 Correct 970 ms 33624 KB Output is correct
96 Correct 952 ms 33500 KB Output is correct
97 Correct 957 ms 33500 KB Output is correct
98 Correct 969 ms 33500 KB Output is correct
99 Correct 968 ms 33508 KB Output is correct
100 Correct 450 ms 17128 KB Output is correct
101 Correct 447 ms 17128 KB Output is correct
102 Correct 442 ms 17128 KB Output is correct
103 Correct 434 ms 17128 KB Output is correct
104 Correct 440 ms 17128 KB Output is correct
105 Correct 617 ms 33484 KB Output is correct
106 Correct 593 ms 33496 KB Output is correct
107 Correct 604 ms 33500 KB Output is correct
108 Correct 612 ms 33496 KB Output is correct
109 Correct 596 ms 33500 KB Output is correct
110 Correct 850 ms 33612 KB Output is correct
111 Correct 875 ms 33648 KB Output is correct
112 Correct 873 ms 33496 KB Output is correct
113 Correct 890 ms 33500 KB Output is correct
114 Correct 889 ms 33636 KB Output is correct
115 Correct 866 ms 33500 KB Output is correct
116 Correct 872 ms 33500 KB Output is correct
117 Correct 856 ms 33500 KB Output is correct
118 Correct 874 ms 33500 KB Output is correct
119 Correct 871 ms 33484 KB Output is correct
120 Correct 5 ms 512 KB Output is correct
121 Correct 5 ms 512 KB Output is correct
122 Correct 977 ms 33508 KB Output is correct
123 Correct 962 ms 33508 KB Output is correct
124 Correct 946 ms 33508 KB Output is correct
125 Correct 962 ms 33508 KB Output is correct
126 Correct 966 ms 33500 KB Output is correct
127 Correct 948 ms 33500 KB Output is correct
128 Correct 952 ms 33500 KB Output is correct
129 Correct 998 ms 33496 KB Output is correct
130 Correct 968 ms 33500 KB Output is correct
131 Correct 945 ms 33500 KB Output is correct
132 Correct 966 ms 33740 KB Output is correct
133 Correct 941 ms 33508 KB Output is correct