답안 #125746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125746 2019-07-06T09:54:09 Z arnold518 Bulldozer (JOI17_bulldozer) C++14
80 / 100
1637 ms 71520 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, z;
    int m1, m2;
};

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

struct SEG
{
    ll ans[4*MAXN+10], lsum[4*MAXN+10], rsum[4*MAXN+10], sum[4*MAXN+10];

    SEG()
    {
        memset(ans, 0, sizeof(ans));
        memset(lsum, 0, sizeof(lsum));
        memset(rsum, 0, sizeof(rsum));
        memset(sum, 0, sizeof(sum));
    }

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

        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];
        ans[node]=max(max(0ll, rsum[node*2]+lsum[node*2+1]), max(ans[node*2], ans[node*2+1]));
    }

    ll query()
    {
        return ans[1];
    }
};
SEG seg;

pll mult(ll a, ll b)
{
    ll k=1e9;
    ll a1=a/k, a2=a%k;
    ll b1=b/k, b2=b%k;

    ll x=a2*b2+(a1*b2+a2*b1)%k, y=a1*b1+(a1*b2+a2*b1)/k;
    y+=x/(k*k);
    x%=k*k;
    return {y, x};
}

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;
        seg.update(1, 1, n, i, mine[i].w);
    }
    ans=seg.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, mine[i].y*mine[j].x-mine[j].y*mine[i].x, 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)
        {
            if(q.x*p.y!=p.x*q.y) return q.x*p.y<p.x*q.y;
            if(mult(q.x, p.z)!=mult(p.x, q.z)) return mult(q.x, p.z)<mult(p.x, q.z);
            if(mine[p.m1].x!=mine[q.m1].x) return mine[p.m1].x<mine[q.m1].x;
            return mine[p.m1].y<mine[q.m1].y;
        });

    for(i=0; i<L.size(); )
    {
        ll x=L[i].x, y=L[i].y, z=L[i].z;
        while(i<L.size() && L[i].x*y==L[i].y*x)
        {
            x=L[i].x, y=L[i].y, z=L[i].z;
            vector<int> todo;
            while(i<L.size() && mult(L[i].x, z)==mult(L[i].z, x))
            {
                todo.push_back(L[i].m1);
                todo.push_back(L[i].m2);
                i++;
            }
            sort(todo.begin(), todo.end());
            todo.erase(unique(todo.begin(), todo.end()), todo.end());
            for(j=0; j<todo.size()/2; j++)
            {
                int m1=todo[j], m2=todo[todo.size()-j-1];
                seg.update(1, 1, n, pos[m1], arr[pos[m2]]);
                seg.update(1, 1, n, pos[m2], arr[pos[m1]]);
                swap(arr[pos[m1]], arr[pos[m2]]);
                swap(pos[m1], pos[m2]);
            }
        }
        ans=max(ans, seg.query());
    }
    printf("%lld", ans);
}

Compilation message

bulldozer.cpp: In member function 'void SEG::update(int, int, int, int, ll)':
bulldozer.cpp:47:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid=tl+tr>>1;
                 ~~^~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:112:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0; i<L.size(); )
              ~^~~~~~~~~
bulldozer.cpp:115: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:119:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(i<L.size() && mult(L[i].x, z)==mult(L[i].z, x))
                   ~^~~~~~~~~
bulldozer.cpp:127:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(j=0; j<todo.size()/2; j++)
                      ~^~~~~~~~~~~~~~
bulldozer.cpp:80:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
bulldozer.cpp:81: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);
                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1016 KB Output is correct
2 Correct 4 ms 1016 KB Output is correct
3 Correct 4 ms 1016 KB Output is correct
4 Correct 4 ms 1016 KB Output is correct
5 Correct 4 ms 1016 KB Output is correct
6 Correct 4 ms 1016 KB Output is correct
7 Correct 4 ms 1016 KB Output is correct
8 Correct 4 ms 1016 KB Output is correct
9 Correct 4 ms 1016 KB Output is correct
10 Correct 4 ms 1016 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 2 ms 508 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1016 KB Output is correct
2 Correct 5 ms 996 KB Output is correct
3 Correct 5 ms 1016 KB Output is correct
4 Correct 5 ms 1016 KB Output is correct
5 Correct 5 ms 1016 KB Output is correct
6 Correct 6 ms 1016 KB Output is correct
7 Correct 5 ms 1016 KB Output is correct
8 Correct 5 ms 1016 KB Output is correct
9 Correct 5 ms 1016 KB Output is correct
10 Correct 5 ms 1016 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 616 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 632 KB Output is correct
17 Correct 2 ms 632 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 632 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 5 ms 1016 KB Output is correct
22 Correct 5 ms 1016 KB Output is correct
23 Correct 5 ms 1016 KB Output is correct
24 Correct 5 ms 1016 KB Output is correct
25 Correct 5 ms 1016 KB Output is correct
26 Correct 5 ms 1016 KB Output is correct
27 Correct 5 ms 1016 KB Output is correct
28 Correct 5 ms 1016 KB Output is correct
29 Correct 5 ms 1016 KB Output is correct
30 Correct 5 ms 1016 KB Output is correct
31 Correct 5 ms 1016 KB Output is correct
32 Correct 9 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1016 KB Output is correct
2 Correct 5 ms 996 KB Output is correct
3 Correct 5 ms 1016 KB Output is correct
4 Correct 5 ms 1016 KB Output is correct
5 Correct 5 ms 1016 KB Output is correct
6 Correct 6 ms 1016 KB Output is correct
7 Correct 5 ms 1016 KB Output is correct
8 Correct 5 ms 1016 KB Output is correct
9 Correct 5 ms 1016 KB Output is correct
10 Correct 5 ms 1016 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 616 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 632 KB Output is correct
17 Correct 2 ms 632 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 632 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 5 ms 1016 KB Output is correct
22 Correct 5 ms 1016 KB Output is correct
23 Correct 5 ms 1016 KB Output is correct
24 Correct 5 ms 1016 KB Output is correct
25 Correct 5 ms 1016 KB Output is correct
26 Correct 5 ms 1016 KB Output is correct
27 Correct 5 ms 1016 KB Output is correct
28 Correct 5 ms 1016 KB Output is correct
29 Correct 5 ms 1016 KB Output is correct
30 Correct 5 ms 1016 KB Output is correct
31 Correct 5 ms 1016 KB Output is correct
32 Correct 9 ms 1016 KB Output is correct
33 Correct 1588 ms 66460 KB Output is correct
34 Correct 1566 ms 66604 KB Output is correct
35 Correct 1576 ms 66456 KB Output is correct
36 Correct 1575 ms 66556 KB Output is correct
37 Correct 1611 ms 66536 KB Output is correct
38 Correct 1574 ms 66456 KB Output is correct
39 Correct 1573 ms 66588 KB Output is correct
40 Correct 1584 ms 66588 KB Output is correct
41 Correct 1582 ms 66456 KB Output is correct
42 Correct 1577 ms 66516 KB Output is correct
43 Correct 1609 ms 66456 KB Output is correct
44 Correct 1563 ms 66584 KB Output is correct
45 Correct 1570 ms 66456 KB Output is correct
46 Correct 1570 ms 66584 KB Output is correct
47 Correct 1559 ms 66484 KB Output is correct
48 Correct 1586 ms 66588 KB Output is correct
49 Correct 1592 ms 66456 KB Output is correct
50 Correct 1580 ms 66632 KB Output is correct
51 Correct 1587 ms 66584 KB Output is correct
52 Correct 1564 ms 66584 KB Output is correct
53 Correct 1559 ms 66456 KB Output is correct
54 Correct 1568 ms 66456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1016 KB Output is correct
2 Correct 5 ms 996 KB Output is correct
3 Correct 5 ms 1016 KB Output is correct
4 Correct 5 ms 1016 KB Output is correct
5 Correct 5 ms 1016 KB Output is correct
6 Correct 6 ms 1016 KB Output is correct
7 Correct 5 ms 1016 KB Output is correct
8 Correct 5 ms 1016 KB Output is correct
9 Correct 5 ms 1016 KB Output is correct
10 Correct 5 ms 1016 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 616 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 632 KB Output is correct
17 Correct 2 ms 632 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 632 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 5 ms 1016 KB Output is correct
22 Correct 5 ms 1016 KB Output is correct
23 Correct 5 ms 1016 KB Output is correct
24 Correct 5 ms 1016 KB Output is correct
25 Correct 5 ms 1016 KB Output is correct
26 Correct 5 ms 1016 KB Output is correct
27 Correct 5 ms 1016 KB Output is correct
28 Correct 5 ms 1016 KB Output is correct
29 Correct 5 ms 1016 KB Output is correct
30 Correct 5 ms 1016 KB Output is correct
31 Correct 5 ms 1016 KB Output is correct
32 Correct 9 ms 1016 KB Output is correct
33 Correct 1588 ms 66460 KB Output is correct
34 Correct 1566 ms 66604 KB Output is correct
35 Correct 1576 ms 66456 KB Output is correct
36 Correct 1575 ms 66556 KB Output is correct
37 Correct 1611 ms 66536 KB Output is correct
38 Correct 1574 ms 66456 KB Output is correct
39 Correct 1573 ms 66588 KB Output is correct
40 Correct 1584 ms 66588 KB Output is correct
41 Correct 1582 ms 66456 KB Output is correct
42 Correct 1577 ms 66516 KB Output is correct
43 Correct 1609 ms 66456 KB Output is correct
44 Correct 1563 ms 66584 KB Output is correct
45 Correct 1570 ms 66456 KB Output is correct
46 Correct 1570 ms 66584 KB Output is correct
47 Correct 1559 ms 66484 KB Output is correct
48 Correct 1586 ms 66588 KB Output is correct
49 Correct 1592 ms 66456 KB Output is correct
50 Correct 1580 ms 66632 KB Output is correct
51 Correct 1587 ms 66584 KB Output is correct
52 Correct 1564 ms 66584 KB Output is correct
53 Correct 1559 ms 66456 KB Output is correct
54 Correct 1568 ms 66456 KB Output is correct
55 Correct 1580 ms 66556 KB Output is correct
56 Correct 1585 ms 66456 KB Output is correct
57 Correct 1637 ms 66456 KB Output is correct
58 Correct 1579 ms 66456 KB Output is correct
59 Correct 1584 ms 66624 KB Output is correct
60 Correct 1587 ms 66456 KB Output is correct
61 Correct 1579 ms 66456 KB Output is correct
62 Correct 1597 ms 66456 KB Output is correct
63 Correct 1595 ms 66456 KB Output is correct
64 Correct 1623 ms 66584 KB Output is correct
65 Correct 1577 ms 66584 KB Output is correct
66 Correct 1582 ms 66584 KB Output is correct
67 Correct 1560 ms 66584 KB Output is correct
68 Correct 1577 ms 66584 KB Output is correct
69 Correct 1567 ms 66460 KB Output is correct
70 Correct 1606 ms 66584 KB Output is correct
71 Correct 1579 ms 66584 KB Output is correct
72 Correct 1585 ms 66588 KB Output is correct
73 Correct 1603 ms 66456 KB Output is correct
74 Correct 1589 ms 66584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1016 KB Output is correct
2 Correct 4 ms 1016 KB Output is correct
3 Correct 4 ms 1016 KB Output is correct
4 Correct 4 ms 1016 KB Output is correct
5 Correct 4 ms 1016 KB Output is correct
6 Correct 4 ms 1016 KB Output is correct
7 Correct 4 ms 1016 KB Output is correct
8 Correct 4 ms 1016 KB Output is correct
9 Correct 4 ms 1016 KB Output is correct
10 Correct 4 ms 1016 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 2 ms 508 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 5 ms 1016 KB Output is correct
17 Correct 5 ms 996 KB Output is correct
18 Correct 5 ms 1016 KB Output is correct
19 Correct 5 ms 1016 KB Output is correct
20 Correct 5 ms 1016 KB Output is correct
21 Correct 6 ms 1016 KB Output is correct
22 Correct 5 ms 1016 KB Output is correct
23 Correct 5 ms 1016 KB Output is correct
24 Correct 5 ms 1016 KB Output is correct
25 Correct 5 ms 1016 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 2 ms 616 KB Output is correct
28 Correct 2 ms 632 KB Output is correct
29 Correct 2 ms 632 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 632 KB Output is correct
32 Correct 2 ms 632 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 632 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 5 ms 1016 KB Output is correct
37 Correct 5 ms 1016 KB Output is correct
38 Correct 5 ms 1016 KB Output is correct
39 Correct 5 ms 1016 KB Output is correct
40 Correct 5 ms 1016 KB Output is correct
41 Correct 5 ms 1016 KB Output is correct
42 Correct 5 ms 1016 KB Output is correct
43 Correct 5 ms 1016 KB Output is correct
44 Correct 5 ms 1016 KB Output is correct
45 Correct 5 ms 1016 KB Output is correct
46 Correct 5 ms 1016 KB Output is correct
47 Correct 9 ms 1016 KB Output is correct
48 Correct 1588 ms 66460 KB Output is correct
49 Correct 1566 ms 66604 KB Output is correct
50 Correct 1576 ms 66456 KB Output is correct
51 Correct 1575 ms 66556 KB Output is correct
52 Correct 1611 ms 66536 KB Output is correct
53 Correct 1574 ms 66456 KB Output is correct
54 Correct 1573 ms 66588 KB Output is correct
55 Correct 1584 ms 66588 KB Output is correct
56 Correct 1582 ms 66456 KB Output is correct
57 Correct 1577 ms 66516 KB Output is correct
58 Correct 1609 ms 66456 KB Output is correct
59 Correct 1563 ms 66584 KB Output is correct
60 Correct 1570 ms 66456 KB Output is correct
61 Correct 1570 ms 66584 KB Output is correct
62 Correct 1559 ms 66484 KB Output is correct
63 Correct 1586 ms 66588 KB Output is correct
64 Correct 1592 ms 66456 KB Output is correct
65 Correct 1580 ms 66632 KB Output is correct
66 Correct 1587 ms 66584 KB Output is correct
67 Correct 1564 ms 66584 KB Output is correct
68 Correct 1559 ms 66456 KB Output is correct
69 Correct 1568 ms 66456 KB Output is correct
70 Correct 1580 ms 66556 KB Output is correct
71 Correct 1585 ms 66456 KB Output is correct
72 Correct 1637 ms 66456 KB Output is correct
73 Correct 1579 ms 66456 KB Output is correct
74 Correct 1584 ms 66624 KB Output is correct
75 Correct 1587 ms 66456 KB Output is correct
76 Correct 1579 ms 66456 KB Output is correct
77 Correct 1597 ms 66456 KB Output is correct
78 Correct 1595 ms 66456 KB Output is correct
79 Correct 1623 ms 66584 KB Output is correct
80 Correct 1577 ms 66584 KB Output is correct
81 Correct 1582 ms 66584 KB Output is correct
82 Correct 1560 ms 66584 KB Output is correct
83 Correct 1577 ms 66584 KB Output is correct
84 Correct 1567 ms 66460 KB Output is correct
85 Correct 1606 ms 66584 KB Output is correct
86 Correct 1579 ms 66584 KB Output is correct
87 Correct 1585 ms 66588 KB Output is correct
88 Correct 1603 ms 66456 KB Output is correct
89 Correct 1589 ms 66584 KB Output is correct
90 Correct 1594 ms 66556 KB Output is correct
91 Correct 1568 ms 66584 KB Output is correct
92 Correct 1588 ms 66456 KB Output is correct
93 Correct 1578 ms 66456 KB Output is correct
94 Correct 1578 ms 66516 KB Output is correct
95 Correct 1573 ms 66552 KB Output is correct
96 Correct 1582 ms 66584 KB Output is correct
97 Correct 1580 ms 66700 KB Output is correct
98 Correct 1569 ms 66588 KB Output is correct
99 Correct 1571 ms 66556 KB Output is correct
100 Incorrect 1201 ms 71520 KB Output isn't correct
101 Halted 0 ms 0 KB -