답안 #843636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
843636 2023-09-04T10:23:58 Z Cookie Bulldozer (JOI17_bulldozer) C++14
100 / 100
789 ms 68296 KB
#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>

const int mxn = 2005;
const ll inf = 1e18, mod = 1e9 + 7;
struct P{
    int x, y; ll w;
    bool operator <(const P &b){
        if(x != b.x)return(x < b.x);
        return(y < b.y);
    }
};
struct E{
    ll x, y, u, v;
    bool operator <(const E &b){
        ll val1 = y * b.x, val2 = b.y * x;
        if(val1 != val2)return(val1 < val2);
        return(make_pair(u, v) < make_pair(b.u, b.v));
    }
};
struct Node{
    ll sm, b, p, s;
};
Node comb(Node a, Node b){
    Node res; 
    res.sm = a.sm + b.sm;
    res.p = max(a.p, a.sm + b.p);
    res.s = max(b.s, b.sm + a.s);
    res.b = max(max(a.b, b.b), a.s + b.p);
    return(res);
}
Node st[(mxn << 2) | 1];
void upd(int nd, int l, int r, int id, ll v){
    if(l > id || r < id)return;
    if(l == r){
        st[nd].p = st[nd].s = st[nd].b = st[nd].sm = v;
        return;
    }
    int mid = (l + r) >> 1;
    upd(nd << 1, l, mid, id, v); upd(nd << 1 | 1, mid + 1, r, id, v);
    st[nd] = comb(st[nd << 1], st[nd << 1 | 1]);
}
Node get(int nd, int l, int r, int ql, int qr){
    if(ql <= l && qr >= r)return(st[nd]);
    int mid = (l + r) >> 1;
    if(ql > mid)return(get(nd << 1 | 1, mid + 1, r, ql, qr));
    else if(qr <= mid)return(get(nd << 1, l, mid, ql, qr));
    return(comb(get(nd << 1, l, mid, ql, qr), get(nd << 1 | 1, mid + 1, r, ql, qr)));
}
int n;
P a[mxn + 1];
vt<E>edge;
int pos[mxn + 1];
signed main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i].x >> a[i].y >> a[i].w; 
    }
    sort(a + 1, a + n + 1);
    for(int i = 1; i <= n; i++){
        pos[i] = i;
        for(int j = i + 1; j <= n; j++){
            edge.pb({a[j].x - a[i].x, a[j].y - a[i].y, i, j});
        }
    }
    sort(edge.begin(), edge.end());
    for(int i = 1; i <= n; i++){
        upd(1, 1, n, i, a[i].w);
    }
    ll ans = max((ll)0, st[1].b);
    for(int i = 0; i < sz(edge);){
        int r = i;
        while(r < sz(edge) && edge[i].y * edge[r].x == edge[r].y * edge[i].x)r++;
        for(int j = i; j < r; j++){
            int u = edge[j].u, v = edge[j].v;
            swap(pos[u], pos[v]);
            upd(1, 1, n, pos[u], a[u].w); upd(1, 1, n, pos[v], a[v].w);
        }
        ans = max(ans, st[1].b);
        i = r;
    }
    cout << ans;
    return(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 2 ms 1016 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 860 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 2 ms 1016 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 860 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 783 ms 66488 KB Output is correct
34 Correct 745 ms 67508 KB Output is correct
35 Correct 772 ms 67008 KB Output is correct
36 Correct 743 ms 67516 KB Output is correct
37 Correct 756 ms 67412 KB Output is correct
38 Correct 737 ms 68016 KB Output is correct
39 Correct 745 ms 67256 KB Output is correct
40 Correct 754 ms 66756 KB Output is correct
41 Correct 754 ms 67260 KB Output is correct
42 Correct 744 ms 66748 KB Output is correct
43 Correct 763 ms 68020 KB Output is correct
44 Correct 744 ms 66224 KB Output is correct
45 Correct 744 ms 67768 KB Output is correct
46 Correct 738 ms 66796 KB Output is correct
47 Correct 739 ms 68292 KB Output is correct
48 Correct 743 ms 67200 KB Output is correct
49 Correct 787 ms 66320 KB Output is correct
50 Correct 747 ms 67772 KB Output is correct
51 Correct 786 ms 67516 KB Output is correct
52 Correct 739 ms 66988 KB Output is correct
53 Correct 738 ms 67260 KB Output is correct
54 Correct 747 ms 67008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 2 ms 1016 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 860 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 783 ms 66488 KB Output is correct
34 Correct 745 ms 67508 KB Output is correct
35 Correct 772 ms 67008 KB Output is correct
36 Correct 743 ms 67516 KB Output is correct
37 Correct 756 ms 67412 KB Output is correct
38 Correct 737 ms 68016 KB Output is correct
39 Correct 745 ms 67256 KB Output is correct
40 Correct 754 ms 66756 KB Output is correct
41 Correct 754 ms 67260 KB Output is correct
42 Correct 744 ms 66748 KB Output is correct
43 Correct 763 ms 68020 KB Output is correct
44 Correct 744 ms 66224 KB Output is correct
45 Correct 744 ms 67768 KB Output is correct
46 Correct 738 ms 66796 KB Output is correct
47 Correct 739 ms 68292 KB Output is correct
48 Correct 743 ms 67200 KB Output is correct
49 Correct 787 ms 66320 KB Output is correct
50 Correct 747 ms 67772 KB Output is correct
51 Correct 786 ms 67516 KB Output is correct
52 Correct 739 ms 66988 KB Output is correct
53 Correct 738 ms 67260 KB Output is correct
54 Correct 747 ms 67008 KB Output is correct
55 Correct 740 ms 66756 KB Output is correct
56 Correct 743 ms 67008 KB Output is correct
57 Correct 758 ms 68284 KB Output is correct
58 Correct 755 ms 67032 KB Output is correct
59 Correct 789 ms 66732 KB Output is correct
60 Correct 778 ms 68296 KB Output is correct
61 Correct 740 ms 68292 KB Output is correct
62 Correct 752 ms 68104 KB Output is correct
63 Correct 755 ms 66956 KB Output is correct
64 Correct 749 ms 68280 KB Output is correct
65 Correct 742 ms 66480 KB Output is correct
66 Correct 765 ms 66492 KB Output is correct
67 Correct 744 ms 68028 KB Output is correct
68 Correct 769 ms 67004 KB Output is correct
69 Correct 738 ms 66492 KB Output is correct
70 Correct 759 ms 67012 KB Output is correct
71 Correct 740 ms 66992 KB Output is correct
72 Correct 770 ms 66748 KB Output is correct
73 Correct 760 ms 66656 KB Output is correct
74 Correct 766 ms 66236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 2 ms 860 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 1016 KB Output is correct
25 Correct 2 ms 860 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 2 ms 860 KB Output is correct
37 Correct 2 ms 860 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 2 ms 860 KB Output is correct
40 Correct 2 ms 860 KB Output is correct
41 Correct 2 ms 860 KB Output is correct
42 Correct 3 ms 860 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 2 ms 860 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Correct 2 ms 860 KB Output is correct
48 Correct 783 ms 66488 KB Output is correct
49 Correct 745 ms 67508 KB Output is correct
50 Correct 772 ms 67008 KB Output is correct
51 Correct 743 ms 67516 KB Output is correct
52 Correct 756 ms 67412 KB Output is correct
53 Correct 737 ms 68016 KB Output is correct
54 Correct 745 ms 67256 KB Output is correct
55 Correct 754 ms 66756 KB Output is correct
56 Correct 754 ms 67260 KB Output is correct
57 Correct 744 ms 66748 KB Output is correct
58 Correct 763 ms 68020 KB Output is correct
59 Correct 744 ms 66224 KB Output is correct
60 Correct 744 ms 67768 KB Output is correct
61 Correct 738 ms 66796 KB Output is correct
62 Correct 739 ms 68292 KB Output is correct
63 Correct 743 ms 67200 KB Output is correct
64 Correct 787 ms 66320 KB Output is correct
65 Correct 747 ms 67772 KB Output is correct
66 Correct 786 ms 67516 KB Output is correct
67 Correct 739 ms 66988 KB Output is correct
68 Correct 738 ms 67260 KB Output is correct
69 Correct 747 ms 67008 KB Output is correct
70 Correct 740 ms 66756 KB Output is correct
71 Correct 743 ms 67008 KB Output is correct
72 Correct 758 ms 68284 KB Output is correct
73 Correct 755 ms 67032 KB Output is correct
74 Correct 789 ms 66732 KB Output is correct
75 Correct 778 ms 68296 KB Output is correct
76 Correct 740 ms 68292 KB Output is correct
77 Correct 752 ms 68104 KB Output is correct
78 Correct 755 ms 66956 KB Output is correct
79 Correct 749 ms 68280 KB Output is correct
80 Correct 742 ms 66480 KB Output is correct
81 Correct 765 ms 66492 KB Output is correct
82 Correct 744 ms 68028 KB Output is correct
83 Correct 769 ms 67004 KB Output is correct
84 Correct 738 ms 66492 KB Output is correct
85 Correct 759 ms 67012 KB Output is correct
86 Correct 740 ms 66992 KB Output is correct
87 Correct 770 ms 66748 KB Output is correct
88 Correct 760 ms 66656 KB Output is correct
89 Correct 766 ms 66236 KB Output is correct
90 Correct 756 ms 66236 KB Output is correct
91 Correct 753 ms 66736 KB Output is correct
92 Correct 746 ms 67248 KB Output is correct
93 Correct 765 ms 66500 KB Output is correct
94 Correct 773 ms 67720 KB Output is correct
95 Correct 755 ms 68276 KB Output is correct
96 Correct 759 ms 67124 KB Output is correct
97 Correct 748 ms 66492 KB Output is correct
98 Correct 743 ms 66616 KB Output is correct
99 Correct 751 ms 67268 KB Output is correct
100 Correct 625 ms 67512 KB Output is correct
101 Correct 626 ms 67604 KB Output is correct
102 Correct 643 ms 67516 KB Output is correct
103 Correct 649 ms 67780 KB Output is correct
104 Correct 636 ms 66492 KB Output is correct
105 Correct 656 ms 67524 KB Output is correct
106 Correct 659 ms 66752 KB Output is correct
107 Correct 652 ms 68036 KB Output is correct
108 Correct 656 ms 67008 KB Output is correct
109 Correct 651 ms 68284 KB Output is correct
110 Correct 717 ms 67508 KB Output is correct
111 Correct 706 ms 66748 KB Output is correct
112 Correct 715 ms 67760 KB Output is correct
113 Correct 713 ms 67268 KB Output is correct
114 Correct 706 ms 66224 KB Output is correct
115 Correct 723 ms 68012 KB Output is correct
116 Correct 717 ms 67248 KB Output is correct
117 Correct 723 ms 67780 KB Output is correct
118 Correct 711 ms 68024 KB Output is correct
119 Correct 717 ms 68028 KB Output is correct
120 Correct 0 ms 348 KB Output is correct
121 Correct 0 ms 348 KB Output is correct
122 Correct 752 ms 67268 KB Output is correct
123 Correct 762 ms 67004 KB Output is correct
124 Correct 763 ms 68036 KB Output is correct
125 Correct 748 ms 66584 KB Output is correct
126 Correct 745 ms 67772 KB Output is correct
127 Correct 781 ms 68012 KB Output is correct
128 Correct 741 ms 66740 KB Output is correct
129 Correct 765 ms 66736 KB Output is correct
130 Correct 755 ms 67080 KB Output is correct
131 Correct 784 ms 67240 KB Output is correct
132 Correct 753 ms 67124 KB Output is correct
133 Correct 754 ms 66756 KB Output is correct