Submission #122710

# Submission time Handle Problem Language Result Execution time Memory
122710 2019-06-29T07:12:13 Z 송준혁(#3002) Bulldozer (JOI17_bulldozer) C++14
100 / 100
1812 ms 63228 KB
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

int N;
int cnt[2020], t, num;
LL ans;

struct Point{
    LL x, y, w;
    int p, q;
} P[2020], E[4040404];

struct Node{
    LL Lmax, Rmax, Sum, Max;
} T[10101];

void update(int id, int s, int e, int t, LL v){
    if (t < s || e < t) return;
    if (s == e){
        T[id].Sum += v;
        T[id].Lmax = max(0ll, T[id].Sum);
        T[id].Rmax = max(0ll, T[id].Sum);
        T[id].Max = max(0ll, T[id].Sum);
        return;
    }
    int mid = (s+e)/2;
    update(id*2, s, mid, t, v);
    update(id*2+1, mid+1, e, t, v);
    T[id].Lmax = max(T[id*2].Lmax, T[id*2].Sum+T[id*2+1].Lmax);
    T[id].Rmax = max(T[id*2+1].Rmax, T[id*2].Rmax+T[id*2+1].Sum);
    T[id].Sum = T[id*2].Sum + T[id*2+1].Sum;
    T[id].Max = max(T[id*2].Max, T[id*2+1].Max);
    T[id].Max = max(T[id].Max, T[id*2].Rmax+T[id*2+1].Lmax);
}

int main(){
    scanf("%d", &N);
    for (int i=1; i<=N; i++) scanf("%lld %lld %lld", &P[i].x, &P[i].y, &P[i].w);
    sort(P+1, P+N+1, [&](Point a, Point b){
        if (a.x == b.x) return a.y > b.y;
        return a.x < b.x;
    });
    for (int i=1; i<N; i++) for (int j=i+1; j<=N; j++){
        num++, cnt[j]++;
        E[num] = (Point){P[j].x-P[i].x, P[j].y-P[i].y, 0, i, j};
    }
    sort(E+1, E+num+1, [&](Point a, Point b){
         if (a.x == 0 && b.x == 0) return a.y < b.y;
         if (a.x == 0) return true;
         if (b.x == 0) return false;
         return a.y*b.x < b.y*a.x;
    });
    for (int i=1; i<=N; i++) update(1, 0, N, cnt[i], P[i].w);
    ans = max(ans, T[1].Max);
    t=1;
    while (t <= num){
        LL dx=E[t].x, dy=E[t].y;
        for (int i=t; i<=num && (E[i].y*dx == dy*E[i].x || (dx == 0 && E[i].x == 0)); i++){
            update(1, 0, N, cnt[E[i].q], -P[E[i].q].w);
            cnt[E[i].q]--;
            update(1, 0, N, cnt[E[i].q], P[E[i].q].w);
        }
        ans = max(ans, T[1].Max);
        for (; t<=num && (E[t].y*dx == dy*E[t].x || (dx == 0 && E[t].x == 0)); t++){
            update(1, 0, N, cnt[E[t].p], -P[E[t].p].w);
            cnt[E[t].p]++;
            update(1, 0, N, cnt[E[t].p], P[E[t].p].w);
        }
        ans = max(ans, T[1].Max);
    }
    printf("%lld\n", ans);
    return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
bulldozer.cpp:39:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i=1; i<=N; i++) scanf("%lld %lld %lld", &P[i].x, &P[i].y, &P[i].w);
                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 4 ms 508 KB Output is correct
7 Correct 4 ms 504 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 4 ms 504 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 4 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 4 ms 504 KB Output is correct
7 Correct 4 ms 508 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 5 ms 508 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 380 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 504 KB Output is correct
22 Correct 4 ms 504 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 4 ms 504 KB Output is correct
25 Correct 4 ms 504 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 4 ms 504 KB Output is correct
32 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 4 ms 504 KB Output is correct
7 Correct 4 ms 508 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 5 ms 508 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 380 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 504 KB Output is correct
22 Correct 4 ms 504 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 4 ms 504 KB Output is correct
25 Correct 4 ms 504 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 4 ms 504 KB Output is correct
32 Correct 5 ms 504 KB Output is correct
33 Correct 1726 ms 63160 KB Output is correct
34 Correct 1696 ms 63152 KB Output is correct
35 Correct 1735 ms 63096 KB Output is correct
36 Correct 1713 ms 63096 KB Output is correct
37 Correct 1733 ms 63164 KB Output is correct
38 Correct 1701 ms 63168 KB Output is correct
39 Correct 1705 ms 63192 KB Output is correct
40 Correct 1703 ms 63156 KB Output is correct
41 Correct 1703 ms 63152 KB Output is correct
42 Correct 1711 ms 63096 KB Output is correct
43 Correct 1738 ms 63156 KB Output is correct
44 Correct 1703 ms 63156 KB Output is correct
45 Correct 1704 ms 63224 KB Output is correct
46 Correct 1700 ms 63152 KB Output is correct
47 Correct 1694 ms 63152 KB Output is correct
48 Correct 1698 ms 63224 KB Output is correct
49 Correct 1806 ms 63156 KB Output is correct
50 Correct 1708 ms 63160 KB Output is correct
51 Correct 1687 ms 63164 KB Output is correct
52 Correct 1699 ms 63168 KB Output is correct
53 Correct 1689 ms 63100 KB Output is correct
54 Correct 1719 ms 63072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 4 ms 504 KB Output is correct
7 Correct 4 ms 508 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 5 ms 508 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 380 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 504 KB Output is correct
22 Correct 4 ms 504 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 4 ms 504 KB Output is correct
25 Correct 4 ms 504 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 4 ms 504 KB Output is correct
32 Correct 5 ms 504 KB Output is correct
33 Correct 1726 ms 63160 KB Output is correct
34 Correct 1696 ms 63152 KB Output is correct
35 Correct 1735 ms 63096 KB Output is correct
36 Correct 1713 ms 63096 KB Output is correct
37 Correct 1733 ms 63164 KB Output is correct
38 Correct 1701 ms 63168 KB Output is correct
39 Correct 1705 ms 63192 KB Output is correct
40 Correct 1703 ms 63156 KB Output is correct
41 Correct 1703 ms 63152 KB Output is correct
42 Correct 1711 ms 63096 KB Output is correct
43 Correct 1738 ms 63156 KB Output is correct
44 Correct 1703 ms 63156 KB Output is correct
45 Correct 1704 ms 63224 KB Output is correct
46 Correct 1700 ms 63152 KB Output is correct
47 Correct 1694 ms 63152 KB Output is correct
48 Correct 1698 ms 63224 KB Output is correct
49 Correct 1806 ms 63156 KB Output is correct
50 Correct 1708 ms 63160 KB Output is correct
51 Correct 1687 ms 63164 KB Output is correct
52 Correct 1699 ms 63168 KB Output is correct
53 Correct 1689 ms 63100 KB Output is correct
54 Correct 1719 ms 63072 KB Output is correct
55 Correct 1703 ms 63164 KB Output is correct
56 Correct 1719 ms 63156 KB Output is correct
57 Correct 1720 ms 63160 KB Output is correct
58 Correct 1723 ms 63188 KB Output is correct
59 Correct 1698 ms 63096 KB Output is correct
60 Correct 1699 ms 63224 KB Output is correct
61 Correct 1703 ms 63152 KB Output is correct
62 Correct 1710 ms 63096 KB Output is correct
63 Correct 1706 ms 63156 KB Output is correct
64 Correct 1701 ms 63068 KB Output is correct
65 Correct 1701 ms 63164 KB Output is correct
66 Correct 1728 ms 63160 KB Output is correct
67 Correct 1720 ms 63152 KB Output is correct
68 Correct 1707 ms 63152 KB Output is correct
69 Correct 1721 ms 63228 KB Output is correct
70 Correct 1717 ms 63160 KB Output is correct
71 Correct 1697 ms 63196 KB Output is correct
72 Correct 1713 ms 63096 KB Output is correct
73 Correct 1699 ms 63156 KB Output is correct
74 Correct 1725 ms 63160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 4 ms 508 KB Output is correct
7 Correct 4 ms 504 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 4 ms 504 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 4 ms 504 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 4 ms 504 KB Output is correct
19 Correct 4 ms 504 KB Output is correct
20 Correct 4 ms 504 KB Output is correct
21 Correct 4 ms 504 KB Output is correct
22 Correct 4 ms 508 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
25 Correct 5 ms 508 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 380 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 504 KB Output is correct
37 Correct 4 ms 504 KB Output is correct
38 Correct 4 ms 504 KB Output is correct
39 Correct 4 ms 504 KB Output is correct
40 Correct 4 ms 504 KB Output is correct
41 Correct 4 ms 504 KB Output is correct
42 Correct 4 ms 504 KB Output is correct
43 Correct 5 ms 504 KB Output is correct
44 Correct 4 ms 504 KB Output is correct
45 Correct 4 ms 632 KB Output is correct
46 Correct 4 ms 504 KB Output is correct
47 Correct 5 ms 504 KB Output is correct
48 Correct 1726 ms 63160 KB Output is correct
49 Correct 1696 ms 63152 KB Output is correct
50 Correct 1735 ms 63096 KB Output is correct
51 Correct 1713 ms 63096 KB Output is correct
52 Correct 1733 ms 63164 KB Output is correct
53 Correct 1701 ms 63168 KB Output is correct
54 Correct 1705 ms 63192 KB Output is correct
55 Correct 1703 ms 63156 KB Output is correct
56 Correct 1703 ms 63152 KB Output is correct
57 Correct 1711 ms 63096 KB Output is correct
58 Correct 1738 ms 63156 KB Output is correct
59 Correct 1703 ms 63156 KB Output is correct
60 Correct 1704 ms 63224 KB Output is correct
61 Correct 1700 ms 63152 KB Output is correct
62 Correct 1694 ms 63152 KB Output is correct
63 Correct 1698 ms 63224 KB Output is correct
64 Correct 1806 ms 63156 KB Output is correct
65 Correct 1708 ms 63160 KB Output is correct
66 Correct 1687 ms 63164 KB Output is correct
67 Correct 1699 ms 63168 KB Output is correct
68 Correct 1689 ms 63100 KB Output is correct
69 Correct 1719 ms 63072 KB Output is correct
70 Correct 1703 ms 63164 KB Output is correct
71 Correct 1719 ms 63156 KB Output is correct
72 Correct 1720 ms 63160 KB Output is correct
73 Correct 1723 ms 63188 KB Output is correct
74 Correct 1698 ms 63096 KB Output is correct
75 Correct 1699 ms 63224 KB Output is correct
76 Correct 1703 ms 63152 KB Output is correct
77 Correct 1710 ms 63096 KB Output is correct
78 Correct 1706 ms 63156 KB Output is correct
79 Correct 1701 ms 63068 KB Output is correct
80 Correct 1701 ms 63164 KB Output is correct
81 Correct 1728 ms 63160 KB Output is correct
82 Correct 1720 ms 63152 KB Output is correct
83 Correct 1707 ms 63152 KB Output is correct
84 Correct 1721 ms 63228 KB Output is correct
85 Correct 1717 ms 63160 KB Output is correct
86 Correct 1697 ms 63196 KB Output is correct
87 Correct 1713 ms 63096 KB Output is correct
88 Correct 1699 ms 63156 KB Output is correct
89 Correct 1725 ms 63160 KB Output is correct
90 Correct 1718 ms 63156 KB Output is correct
91 Correct 1710 ms 63156 KB Output is correct
92 Correct 1717 ms 63156 KB Output is correct
93 Correct 1717 ms 63224 KB Output is correct
94 Correct 1698 ms 63156 KB Output is correct
95 Correct 1721 ms 63224 KB Output is correct
96 Correct 1709 ms 63192 KB Output is correct
97 Correct 1703 ms 63196 KB Output is correct
98 Correct 1694 ms 63156 KB Output is correct
99 Correct 1708 ms 63224 KB Output is correct
100 Correct 1605 ms 63160 KB Output is correct
101 Correct 1568 ms 63196 KB Output is correct
102 Correct 1575 ms 63156 KB Output is correct
103 Correct 1574 ms 63156 KB Output is correct
104 Correct 1587 ms 63168 KB Output is correct
105 Correct 1596 ms 63160 KB Output is correct
106 Correct 1621 ms 63156 KB Output is correct
107 Correct 1623 ms 63156 KB Output is correct
108 Correct 1614 ms 63184 KB Output is correct
109 Correct 1604 ms 63096 KB Output is correct
110 Correct 1582 ms 63160 KB Output is correct
111 Correct 1601 ms 63160 KB Output is correct
112 Correct 1593 ms 63096 KB Output is correct
113 Correct 1583 ms 63160 KB Output is correct
114 Correct 1589 ms 63160 KB Output is correct
115 Correct 1611 ms 63224 KB Output is correct
116 Correct 1589 ms 63224 KB Output is correct
117 Correct 1605 ms 63160 KB Output is correct
118 Correct 1586 ms 63224 KB Output is correct
119 Correct 1603 ms 63224 KB Output is correct
120 Correct 2 ms 376 KB Output is correct
121 Correct 2 ms 256 KB Output is correct
122 Correct 1737 ms 63152 KB Output is correct
123 Correct 1723 ms 63096 KB Output is correct
124 Correct 1812 ms 63224 KB Output is correct
125 Correct 1744 ms 63096 KB Output is correct
126 Correct 1723 ms 63164 KB Output is correct
127 Correct 1714 ms 63096 KB Output is correct
128 Correct 1712 ms 63196 KB Output is correct
129 Correct 1741 ms 63096 KB Output is correct
130 Correct 1747 ms 63160 KB Output is correct
131 Correct 1716 ms 63196 KB Output is correct
132 Correct 1721 ms 63224 KB Output is correct
133 Correct 1688 ms 63160 KB Output is correct