Submission #127557

# Submission time Handle Problem Language Result Execution time Memory
127557 2019-07-09T14:55:05 Z arnold518 Bulldozer (JOI17_bulldozer) C++14
100 / 100
1997 ms 50144 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2000;

struct Mine
{
    ll x, y, w;
};

struct Line
{
    ll x, y;
    int m1, m2;
};

int n, pos[MAXN+10];
Mine mine[MAXN+10];
ll arr[MAXN+10], ans;

ll val[4*MAXN+10], lsum[4*MAXN+10], rsum[4*MAXN+10], sum[4*MAXN+10];

void update(int node, int tl, int tr, int pos, ll dif)
{
    if(pos<tl || tr<pos) return;
    if(tl==tr)
    {
        sum[node]+=dif;
        val[node]=max(0ll, sum[node]);
        lsum[node]=max(0ll, sum[node]);
        rsum[node]=max(0ll, sum[node]);
        return;
    }
    int mid=tl+tr>>1;
    update(node*2, tl, mid, pos, dif);
    update(node*2+1, mid+1, tr, pos, dif);

    lsum[node]=max(lsum[node*2], sum[node*2]+lsum[node*2+1]);
    rsum[node]=max(rsum[node*2+1], sum[node*2+1]+rsum[node*2]);
    sum[node]=sum[node*2]+sum[node*2+1];
    val[node]=max(rsum[node*2]+lsum[node*2+1], max(val[node*2], val[node*2+1]));
}

ll query() { return val[1]; }

int main()
{
    int i, j;

    scanf("%d", &n);
    for(i=1; i<=n; i++) scanf("%lld%lld%lld", &mine[i].x, &mine[i].y, &mine[i].w);
    sort(mine+1, mine+n+1, [&](const Mine p, const Mine q)
        {
            if(p.x!=q.x) return p.x<q.x;
            return p.y<q.y;
        });

    for(i=1; i<=n; i++)
    {
        pos[i]=i;
        arr[i]=mine[i].w;
        update(1, 1, n, i, mine[i].w);
    }
    ans=query();

    vector<Line> L;
    for(i=1; i<=n; i++) for(j=i+1; j<=n; j++)
    {
        Line now={mine[i].x-mine[j].x, mine[i].y-mine[j].y, i, j};
        if(now.x<0) now.x*=-1, now.y*=-1;
        if(now.x==0 && now.y<0) now.y*=-1;
        L.push_back(now);
    }
    sort(L.begin(), L.end(), [&](const Line p, const Line q)
        {
            return q.x*p.y<p.x*q.y;
        });

    for(i=0; i<L.size(); )
    {
        ll x=L[i].x, y=L[i].y;
        while(i<L.size() && L[i].x*y==L[i].y*x)
        {
            int m1=L[i].m1, m2=L[i].m2;

            update(1, 1, n, pos[m2], -mine[m2].w);
            pos[m2]--;
            update(1, 1, n, pos[m2], mine[m2].w);

            update(1, 1, n, pos[m1], -mine[m1].w);
            pos[m1]++;
            update(1, 1, n, pos[m1], mine[m1].w);
            i++;
        }
        ans=max(ans, query());
    }
    printf("%lld", ans);
}

Compilation message

bulldozer.cpp: In function 'void update(int, int, int, int, ll)':
bulldozer.cpp:38:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=tl+tr>>1;
             ~~^~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:83:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0; i<L.size(); )
              ~^~~~~~~~~
bulldozer.cpp:86:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(i<L.size() && L[i].x*y==L[i].y*x)
               ~^~~~~~~~~
bulldozer.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
bulldozer.cpp:55:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=n; i++) scanf("%lld%lld%lld", &mine[i].x, &mine[i].y, &mine[i].w);
                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 636 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 5 ms 632 KB Output is correct
6 Correct 5 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 676 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 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 5 ms 636 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 5 ms 632 KB Output is correct
6 Correct 5 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 632 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 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 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 5 ms 632 KB Output is correct
22 Correct 6 ms 632 KB Output is correct
23 Correct 6 ms 632 KB Output is correct
24 Correct 5 ms 632 KB Output is correct
25 Correct 5 ms 636 KB Output is correct
26 Correct 5 ms 632 KB Output is correct
27 Correct 5 ms 632 KB Output is correct
28 Correct 5 ms 632 KB Output is correct
29 Correct 5 ms 632 KB Output is correct
30 Correct 5 ms 632 KB Output is correct
31 Correct 5 ms 632 KB Output is correct
32 Correct 5 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 5 ms 636 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 5 ms 632 KB Output is correct
6 Correct 5 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 632 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 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 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 5 ms 632 KB Output is correct
22 Correct 6 ms 632 KB Output is correct
23 Correct 6 ms 632 KB Output is correct
24 Correct 5 ms 632 KB Output is correct
25 Correct 5 ms 636 KB Output is correct
26 Correct 5 ms 632 KB Output is correct
27 Correct 5 ms 632 KB Output is correct
28 Correct 5 ms 632 KB Output is correct
29 Correct 5 ms 632 KB Output is correct
30 Correct 5 ms 632 KB Output is correct
31 Correct 5 ms 632 KB Output is correct
32 Correct 5 ms 632 KB Output is correct
33 Correct 1981 ms 49956 KB Output is correct
34 Correct 1964 ms 49964 KB Output is correct
35 Correct 1975 ms 49964 KB Output is correct
36 Correct 1951 ms 50064 KB Output is correct
37 Correct 1961 ms 50144 KB Output is correct
38 Correct 1960 ms 50092 KB Output is correct
39 Correct 1951 ms 50012 KB Output is correct
40 Correct 1969 ms 49964 KB Output is correct
41 Correct 1966 ms 50136 KB Output is correct
42 Correct 1969 ms 50092 KB Output is correct
43 Correct 1959 ms 50020 KB Output is correct
44 Correct 1944 ms 50092 KB Output is correct
45 Correct 1938 ms 50064 KB Output is correct
46 Correct 1953 ms 49964 KB Output is correct
47 Correct 1956 ms 49964 KB Output is correct
48 Correct 1945 ms 49964 KB Output is correct
49 Correct 1957 ms 49964 KB Output is correct
50 Correct 1965 ms 49964 KB Output is correct
51 Correct 1962 ms 49964 KB Output is correct
52 Correct 1966 ms 50004 KB Output is correct
53 Correct 1951 ms 49964 KB Output is correct
54 Correct 1993 ms 49968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 5 ms 636 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 5 ms 632 KB Output is correct
6 Correct 5 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 632 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 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 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 5 ms 632 KB Output is correct
22 Correct 6 ms 632 KB Output is correct
23 Correct 6 ms 632 KB Output is correct
24 Correct 5 ms 632 KB Output is correct
25 Correct 5 ms 636 KB Output is correct
26 Correct 5 ms 632 KB Output is correct
27 Correct 5 ms 632 KB Output is correct
28 Correct 5 ms 632 KB Output is correct
29 Correct 5 ms 632 KB Output is correct
30 Correct 5 ms 632 KB Output is correct
31 Correct 5 ms 632 KB Output is correct
32 Correct 5 ms 632 KB Output is correct
33 Correct 1981 ms 49956 KB Output is correct
34 Correct 1964 ms 49964 KB Output is correct
35 Correct 1975 ms 49964 KB Output is correct
36 Correct 1951 ms 50064 KB Output is correct
37 Correct 1961 ms 50144 KB Output is correct
38 Correct 1960 ms 50092 KB Output is correct
39 Correct 1951 ms 50012 KB Output is correct
40 Correct 1969 ms 49964 KB Output is correct
41 Correct 1966 ms 50136 KB Output is correct
42 Correct 1969 ms 50092 KB Output is correct
43 Correct 1959 ms 50020 KB Output is correct
44 Correct 1944 ms 50092 KB Output is correct
45 Correct 1938 ms 50064 KB Output is correct
46 Correct 1953 ms 49964 KB Output is correct
47 Correct 1956 ms 49964 KB Output is correct
48 Correct 1945 ms 49964 KB Output is correct
49 Correct 1957 ms 49964 KB Output is correct
50 Correct 1965 ms 49964 KB Output is correct
51 Correct 1962 ms 49964 KB Output is correct
52 Correct 1966 ms 50004 KB Output is correct
53 Correct 1951 ms 49964 KB Output is correct
54 Correct 1993 ms 49968 KB Output is correct
55 Correct 1976 ms 50080 KB Output is correct
56 Correct 1951 ms 50028 KB Output is correct
57 Correct 1989 ms 50096 KB Output is correct
58 Correct 1954 ms 49964 KB Output is correct
59 Correct 1953 ms 49964 KB Output is correct
60 Correct 1965 ms 49964 KB Output is correct
61 Correct 1961 ms 49988 KB Output is correct
62 Correct 1994 ms 50092 KB Output is correct
63 Correct 1954 ms 49964 KB Output is correct
64 Correct 1967 ms 50020 KB Output is correct
65 Correct 1979 ms 49964 KB Output is correct
66 Correct 1948 ms 49964 KB Output is correct
67 Correct 1947 ms 49964 KB Output is correct
68 Correct 1963 ms 49964 KB Output is correct
69 Correct 1965 ms 49964 KB Output is correct
70 Correct 1974 ms 49964 KB Output is correct
71 Correct 1958 ms 49968 KB Output is correct
72 Correct 1959 ms 49964 KB Output is correct
73 Correct 1965 ms 50112 KB Output is correct
74 Correct 1958 ms 50092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 636 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 5 ms 632 KB Output is correct
6 Correct 5 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 676 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 376 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 5 ms 636 KB Output is correct
19 Correct 5 ms 632 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 5 ms 632 KB Output is correct
22 Correct 5 ms 632 KB Output is correct
23 Correct 5 ms 632 KB Output is correct
24 Correct 5 ms 632 KB Output is correct
25 Correct 5 ms 632 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 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 2 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 5 ms 632 KB Output is correct
37 Correct 6 ms 632 KB Output is correct
38 Correct 6 ms 632 KB Output is correct
39 Correct 5 ms 632 KB Output is correct
40 Correct 5 ms 636 KB Output is correct
41 Correct 5 ms 632 KB Output is correct
42 Correct 5 ms 632 KB Output is correct
43 Correct 5 ms 632 KB Output is correct
44 Correct 5 ms 632 KB Output is correct
45 Correct 5 ms 632 KB Output is correct
46 Correct 5 ms 632 KB Output is correct
47 Correct 5 ms 632 KB Output is correct
48 Correct 1981 ms 49956 KB Output is correct
49 Correct 1964 ms 49964 KB Output is correct
50 Correct 1975 ms 49964 KB Output is correct
51 Correct 1951 ms 50064 KB Output is correct
52 Correct 1961 ms 50144 KB Output is correct
53 Correct 1960 ms 50092 KB Output is correct
54 Correct 1951 ms 50012 KB Output is correct
55 Correct 1969 ms 49964 KB Output is correct
56 Correct 1966 ms 50136 KB Output is correct
57 Correct 1969 ms 50092 KB Output is correct
58 Correct 1959 ms 50020 KB Output is correct
59 Correct 1944 ms 50092 KB Output is correct
60 Correct 1938 ms 50064 KB Output is correct
61 Correct 1953 ms 49964 KB Output is correct
62 Correct 1956 ms 49964 KB Output is correct
63 Correct 1945 ms 49964 KB Output is correct
64 Correct 1957 ms 49964 KB Output is correct
65 Correct 1965 ms 49964 KB Output is correct
66 Correct 1962 ms 49964 KB Output is correct
67 Correct 1966 ms 50004 KB Output is correct
68 Correct 1951 ms 49964 KB Output is correct
69 Correct 1993 ms 49968 KB Output is correct
70 Correct 1976 ms 50080 KB Output is correct
71 Correct 1951 ms 50028 KB Output is correct
72 Correct 1989 ms 50096 KB Output is correct
73 Correct 1954 ms 49964 KB Output is correct
74 Correct 1953 ms 49964 KB Output is correct
75 Correct 1965 ms 49964 KB Output is correct
76 Correct 1961 ms 49988 KB Output is correct
77 Correct 1994 ms 50092 KB Output is correct
78 Correct 1954 ms 49964 KB Output is correct
79 Correct 1967 ms 50020 KB Output is correct
80 Correct 1979 ms 49964 KB Output is correct
81 Correct 1948 ms 49964 KB Output is correct
82 Correct 1947 ms 49964 KB Output is correct
83 Correct 1963 ms 49964 KB Output is correct
84 Correct 1965 ms 49964 KB Output is correct
85 Correct 1974 ms 49964 KB Output is correct
86 Correct 1958 ms 49968 KB Output is correct
87 Correct 1959 ms 49964 KB Output is correct
88 Correct 1965 ms 50112 KB Output is correct
89 Correct 1958 ms 50092 KB Output is correct
90 Correct 1971 ms 49936 KB Output is correct
91 Correct 1960 ms 49960 KB Output is correct
92 Correct 1970 ms 49968 KB Output is correct
93 Correct 1968 ms 49964 KB Output is correct
94 Correct 1989 ms 49980 KB Output is correct
95 Correct 1959 ms 49964 KB Output is correct
96 Correct 1952 ms 49964 KB Output is correct
97 Correct 1958 ms 49964 KB Output is correct
98 Correct 1955 ms 49964 KB Output is correct
99 Correct 1997 ms 49968 KB Output is correct
100 Correct 1716 ms 49964 KB Output is correct
101 Correct 1738 ms 50092 KB Output is correct
102 Correct 1719 ms 49964 KB Output is correct
103 Correct 1717 ms 49964 KB Output is correct
104 Correct 1718 ms 50124 KB Output is correct
105 Correct 1801 ms 49960 KB Output is correct
106 Correct 1776 ms 49968 KB Output is correct
107 Correct 1778 ms 49964 KB Output is correct
108 Correct 1785 ms 49936 KB Output is correct
109 Correct 1773 ms 49964 KB Output is correct
110 Correct 1771 ms 50092 KB Output is correct
111 Correct 1784 ms 49964 KB Output is correct
112 Correct 1774 ms 49964 KB Output is correct
113 Correct 1784 ms 49964 KB Output is correct
114 Correct 1796 ms 49968 KB Output is correct
115 Correct 1788 ms 49964 KB Output is correct
116 Correct 1776 ms 49964 KB Output is correct
117 Correct 1773 ms 49968 KB Output is correct
118 Correct 1803 ms 50024 KB Output is correct
119 Correct 1783 ms 49968 KB Output is correct
120 Correct 2 ms 376 KB Output is correct
121 Correct 2 ms 376 KB Output is correct
122 Correct 1972 ms 50092 KB Output is correct
123 Correct 1953 ms 49968 KB Output is correct
124 Correct 1949 ms 49964 KB Output is correct
125 Correct 1970 ms 49964 KB Output is correct
126 Correct 1942 ms 50088 KB Output is correct
127 Correct 1950 ms 49936 KB Output is correct
128 Correct 1942 ms 49964 KB Output is correct
129 Correct 1970 ms 49964 KB Output is correct
130 Correct 1970 ms 49964 KB Output is correct
131 Correct 1944 ms 49964 KB Output is correct
132 Correct 1949 ms 49968 KB Output is correct
133 Correct 1947 ms 49964 KB Output is correct