답안 #590609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590609 2022-07-06T07:27:52 Z 반딧불(#8412) Bulldozer (JOI17_bulldozer) C++17
100 / 100
1607 ms 161408 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Node{
    ll prf, suf, ans, sum;
    Node(){}
    Node(ll v){
        prf = suf = ans = max(v, 0LL);
        sum = v;
    }
    Node(ll prf, ll suf, ll ans, ll sum): prf(prf), suf(suf), ans(ans), sum(sum){}

    Node operator+(const Node &r)const{
        return Node(max(prf, sum+r.prf), max(r.suf, suf+r.sum), max({ans, r.ans, suf+r.prf}), sum+r.sum);
    }
};

struct segTree{
    Node tree[8002];

    void update(int i, int l, int r, int x, ll v){
        if(l==r){
            tree[i] = Node(v);
            return;
        }
        int m = (l+r)>>1;
        if(x<=m) update(i*2, l, m, x, v);
        else update(i*2+1, m+1, r, x, v);
        tree[i] = tree[i*2] + tree[i*2+1];
    }

    ll query(){
        return tree[1].ans;
    }
} tree;

struct vector2{
    ll x, y, v;
    int idx;
    vector2(){}
    vector2(ll x, ll y): x(x), y(y){}
    vector2(ll x, ll y, ll v): x(x), y(y), v(v){}

    vector2 operator-(const vector2 r)const{
        return vector2(x-r.x, y-r.y);
    }

    bool operator==(const vector2 r)const{
        return x==r.x && y==r.y;
    }

    vector2 inv(){
        return vector2(y, -x);
    }

    vector2 simplify(){
        vector2 ret = *this;
        ll g = __gcd(ret.x, ret.y);
        ret.x/=g, ret.y/=g;
        if(make_pair(0LL, 0LL) > make_pair(ret.y, ret.x)) ret.x*=-1, ret.y*=-1;
//        printf("(%lld, %lld) simplified\n", ret.x, ret.y);
        return ret;
    }

    ll dot(vector2 r)const{
        return x*r.x + y*r.y;
    }

    ll cross(vector2 r)const{
        return x*r.y - y*r.x;
    }

    ll dist(vector2 r)const{
        return (x-r.x)*(x-r.x)+(y-r.y)*(y-r.y);
    }
} arr[2002];
const vector2 Base (2000000001, -1);

ll ccw(vector2 a, vector2 b){
    return a.cross(b);
}

ll ccw(vector2 a, vector2 b, vector2 c){
    return (b-a).cross(c-a);
}

struct dat{
    vector2 slope;
    int x, y;
    dat(){}
    dat(vector2 slope, int x, int y): slope(slope), x(x), y(y){}

    bool operator<(const dat &r)const{
        ll tmp = ccw(slope, vector2(0, 0), r.slope);
        return tmp<0;
//        if(tmp) return tmp<0;
//        return arr[x].dist(arr[y]) < arr[r.x].dist(arr[r.y]);
    }
};

int n;
int idx[2002];
vector<dat> vec;
ll ans;

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%lld %lld %lld", &arr[i].x, &arr[i].y, &arr[i].v);
    }
    sort(arr+1, arr+n+1, [&](auto A, auto B){
        return Base.dot(A) < Base.dot(B);
    });
    for(int i=1; i<=n; i++){
        tree.update(1, 1, n, i, arr[i].v);
        arr[i].idx = i;
        idx[i] = i;
    }

    for(int i=1; i<=n; i++){
        for(int j=i+1; j<=n; j++){
            vec.push_back(dat((arr[i]-arr[j]).inv().simplify(), i, j));
        }
    }
    sort(vec.begin(), vec.end());

    vector<dat> vec2;
    for(int ti=0; ti<(int)vec.size(); ti++){
        vector2 slope = vec[ti].slope;
        vector2 slopeInv = slope.inv();
        vector<int> indices;
        int tj = ti;
        while(tj < (int)vec.size()-1 && vec[tj+1].slope == slope) tj++;
        for(int i=ti; i<=tj; i++) indices.push_back(vec[i].x), indices.push_back(vec[i].y);
        sort(indices.begin(), indices.end(), [&](int X, int Y){
            ll Xd = arr[X].dot(slope), Yd = arr[Y].dot(slope);
            if(Xd != Yd) return Xd < Yd;
            return arr[X].dot(slopeInv) < arr[Y].dot(slopeInv);
        });
        indices.erase(unique(indices.begin(), indices.end()), indices.end());

//        for(auto x: indices) printf("%d ", x);
//        puts("");

        for(int i=0; i<(int)indices.size(); i++){
            int j = i+1;
            while(j+1 < (int)indices.size() && ccw(arr[indices[i]], arr[indices[j]], arr[indices[j+1]]) == 0) j++;
            for(int a=i, b=j; a<b; a++, b--){
                vec2.push_back(dat(slope, indices[a], indices[b]));
            }
            i=j;
        }
        ti = tj;
    }
    vec.swap(vec2);

    ans = max(ans, tree.query());
    for(int ti=0; ti<(int)vec.size(); ti++){
        dat tmp = vec[ti];
        int X = tmp.x, Y = tmp.y;
//        printf("Swap %d %d (%lld, %lld) - %lld\n", X, Y, tmp.slope.x, tmp.slope.y, arr[tmp.x].dist(arr[tmp.y]));
//        assert(abs(idx[X] - idx[Y]) == 1);
        swap(idx[X], idx[Y]);
        tree.update(1, 1, n, idx[X], arr[X].v);
        tree.update(1, 1, n, idx[Y], arr[Y].v);
        if(ti < (int)vec.size()-1 && vec[ti+1].slope == tmp.slope) continue;
        ans = max(ans, tree.query());
//        printf("Now Ans: %lld\n", ans);
    }

    printf("%lld", ans);
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:110:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
bulldozer.cpp:112:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |         scanf("%lld %lld %lld", &arr[i].x, &arr[i].y, &arr[i].v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 692 KB Output is correct
2 Correct 2 ms 692 KB Output is correct
3 Correct 2 ms 692 KB Output is correct
4 Correct 3 ms 692 KB Output is correct
5 Correct 3 ms 692 KB Output is correct
6 Correct 2 ms 692 KB Output is correct
7 Correct 3 ms 676 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 788 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 912 KB Output is correct
2 Correct 3 ms 912 KB Output is correct
3 Correct 3 ms 912 KB Output is correct
4 Correct 4 ms 912 KB Output is correct
5 Correct 4 ms 912 KB Output is correct
6 Correct 3 ms 912 KB Output is correct
7 Correct 4 ms 912 KB Output is correct
8 Correct 3 ms 912 KB Output is correct
9 Correct 4 ms 904 KB Output is correct
10 Correct 3 ms 912 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 3 ms 912 KB Output is correct
22 Correct 3 ms 912 KB Output is correct
23 Correct 3 ms 912 KB Output is correct
24 Correct 3 ms 912 KB Output is correct
25 Correct 3 ms 912 KB Output is correct
26 Correct 4 ms 912 KB Output is correct
27 Correct 3 ms 912 KB Output is correct
28 Correct 2 ms 912 KB Output is correct
29 Correct 3 ms 956 KB Output is correct
30 Correct 4 ms 912 KB Output is correct
31 Correct 3 ms 912 KB Output is correct
32 Correct 3 ms 912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 912 KB Output is correct
2 Correct 3 ms 912 KB Output is correct
3 Correct 3 ms 912 KB Output is correct
4 Correct 4 ms 912 KB Output is correct
5 Correct 4 ms 912 KB Output is correct
6 Correct 3 ms 912 KB Output is correct
7 Correct 4 ms 912 KB Output is correct
8 Correct 3 ms 912 KB Output is correct
9 Correct 4 ms 904 KB Output is correct
10 Correct 3 ms 912 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 3 ms 912 KB Output is correct
22 Correct 3 ms 912 KB Output is correct
23 Correct 3 ms 912 KB Output is correct
24 Correct 3 ms 912 KB Output is correct
25 Correct 3 ms 912 KB Output is correct
26 Correct 4 ms 912 KB Output is correct
27 Correct 3 ms 912 KB Output is correct
28 Correct 2 ms 912 KB Output is correct
29 Correct 3 ms 956 KB Output is correct
30 Correct 4 ms 912 KB Output is correct
31 Correct 3 ms 912 KB Output is correct
32 Correct 3 ms 912 KB Output is correct
33 Correct 1355 ms 160936 KB Output is correct
34 Correct 1224 ms 160864 KB Output is correct
35 Correct 1317 ms 160916 KB Output is correct
36 Correct 1346 ms 160924 KB Output is correct
37 Correct 1345 ms 160916 KB Output is correct
38 Correct 1390 ms 160880 KB Output is correct
39 Correct 1326 ms 160880 KB Output is correct
40 Correct 1368 ms 160836 KB Output is correct
41 Correct 1350 ms 160872 KB Output is correct
42 Correct 1405 ms 160892 KB Output is correct
43 Correct 1342 ms 160888 KB Output is correct
44 Correct 1290 ms 160904 KB Output is correct
45 Correct 1234 ms 160916 KB Output is correct
46 Correct 1413 ms 160832 KB Output is correct
47 Correct 1252 ms 160964 KB Output is correct
48 Correct 1416 ms 160924 KB Output is correct
49 Correct 1294 ms 160836 KB Output is correct
50 Correct 1266 ms 160960 KB Output is correct
51 Correct 1303 ms 160872 KB Output is correct
52 Correct 1220 ms 160896 KB Output is correct
53 Correct 1290 ms 160892 KB Output is correct
54 Correct 1239 ms 160860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 912 KB Output is correct
2 Correct 3 ms 912 KB Output is correct
3 Correct 3 ms 912 KB Output is correct
4 Correct 4 ms 912 KB Output is correct
5 Correct 4 ms 912 KB Output is correct
6 Correct 3 ms 912 KB Output is correct
7 Correct 4 ms 912 KB Output is correct
8 Correct 3 ms 912 KB Output is correct
9 Correct 4 ms 904 KB Output is correct
10 Correct 3 ms 912 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 3 ms 912 KB Output is correct
22 Correct 3 ms 912 KB Output is correct
23 Correct 3 ms 912 KB Output is correct
24 Correct 3 ms 912 KB Output is correct
25 Correct 3 ms 912 KB Output is correct
26 Correct 4 ms 912 KB Output is correct
27 Correct 3 ms 912 KB Output is correct
28 Correct 2 ms 912 KB Output is correct
29 Correct 3 ms 956 KB Output is correct
30 Correct 4 ms 912 KB Output is correct
31 Correct 3 ms 912 KB Output is correct
32 Correct 3 ms 912 KB Output is correct
33 Correct 1355 ms 160936 KB Output is correct
34 Correct 1224 ms 160864 KB Output is correct
35 Correct 1317 ms 160916 KB Output is correct
36 Correct 1346 ms 160924 KB Output is correct
37 Correct 1345 ms 160916 KB Output is correct
38 Correct 1390 ms 160880 KB Output is correct
39 Correct 1326 ms 160880 KB Output is correct
40 Correct 1368 ms 160836 KB Output is correct
41 Correct 1350 ms 160872 KB Output is correct
42 Correct 1405 ms 160892 KB Output is correct
43 Correct 1342 ms 160888 KB Output is correct
44 Correct 1290 ms 160904 KB Output is correct
45 Correct 1234 ms 160916 KB Output is correct
46 Correct 1413 ms 160832 KB Output is correct
47 Correct 1252 ms 160964 KB Output is correct
48 Correct 1416 ms 160924 KB Output is correct
49 Correct 1294 ms 160836 KB Output is correct
50 Correct 1266 ms 160960 KB Output is correct
51 Correct 1303 ms 160872 KB Output is correct
52 Correct 1220 ms 160896 KB Output is correct
53 Correct 1290 ms 160892 KB Output is correct
54 Correct 1239 ms 160860 KB Output is correct
55 Correct 1284 ms 160828 KB Output is correct
56 Correct 1319 ms 160868 KB Output is correct
57 Correct 1345 ms 160832 KB Output is correct
58 Correct 1287 ms 160912 KB Output is correct
59 Correct 1430 ms 160916 KB Output is correct
60 Correct 1330 ms 160840 KB Output is correct
61 Correct 1332 ms 160912 KB Output is correct
62 Correct 1315 ms 160868 KB Output is correct
63 Correct 1339 ms 160860 KB Output is correct
64 Correct 1268 ms 160860 KB Output is correct
65 Correct 1303 ms 160844 KB Output is correct
66 Correct 1319 ms 160956 KB Output is correct
67 Correct 1312 ms 161028 KB Output is correct
68 Correct 1300 ms 160952 KB Output is correct
69 Correct 1384 ms 160960 KB Output is correct
70 Correct 1432 ms 161068 KB Output is correct
71 Correct 1336 ms 161020 KB Output is correct
72 Correct 1357 ms 160932 KB Output is correct
73 Correct 1364 ms 160908 KB Output is correct
74 Correct 1607 ms 160864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 692 KB Output is correct
2 Correct 2 ms 692 KB Output is correct
3 Correct 2 ms 692 KB Output is correct
4 Correct 3 ms 692 KB Output is correct
5 Correct 3 ms 692 KB Output is correct
6 Correct 2 ms 692 KB Output is correct
7 Correct 3 ms 676 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 788 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 912 KB Output is correct
17 Correct 3 ms 912 KB Output is correct
18 Correct 3 ms 912 KB Output is correct
19 Correct 4 ms 912 KB Output is correct
20 Correct 4 ms 912 KB Output is correct
21 Correct 3 ms 912 KB Output is correct
22 Correct 4 ms 912 KB Output is correct
23 Correct 3 ms 912 KB Output is correct
24 Correct 4 ms 904 KB Output is correct
25 Correct 3 ms 912 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 3 ms 912 KB Output is correct
37 Correct 3 ms 912 KB Output is correct
38 Correct 3 ms 912 KB Output is correct
39 Correct 3 ms 912 KB Output is correct
40 Correct 3 ms 912 KB Output is correct
41 Correct 4 ms 912 KB Output is correct
42 Correct 3 ms 912 KB Output is correct
43 Correct 2 ms 912 KB Output is correct
44 Correct 3 ms 956 KB Output is correct
45 Correct 4 ms 912 KB Output is correct
46 Correct 3 ms 912 KB Output is correct
47 Correct 3 ms 912 KB Output is correct
48 Correct 1355 ms 160936 KB Output is correct
49 Correct 1224 ms 160864 KB Output is correct
50 Correct 1317 ms 160916 KB Output is correct
51 Correct 1346 ms 160924 KB Output is correct
52 Correct 1345 ms 160916 KB Output is correct
53 Correct 1390 ms 160880 KB Output is correct
54 Correct 1326 ms 160880 KB Output is correct
55 Correct 1368 ms 160836 KB Output is correct
56 Correct 1350 ms 160872 KB Output is correct
57 Correct 1405 ms 160892 KB Output is correct
58 Correct 1342 ms 160888 KB Output is correct
59 Correct 1290 ms 160904 KB Output is correct
60 Correct 1234 ms 160916 KB Output is correct
61 Correct 1413 ms 160832 KB Output is correct
62 Correct 1252 ms 160964 KB Output is correct
63 Correct 1416 ms 160924 KB Output is correct
64 Correct 1294 ms 160836 KB Output is correct
65 Correct 1266 ms 160960 KB Output is correct
66 Correct 1303 ms 160872 KB Output is correct
67 Correct 1220 ms 160896 KB Output is correct
68 Correct 1290 ms 160892 KB Output is correct
69 Correct 1239 ms 160860 KB Output is correct
70 Correct 1284 ms 160828 KB Output is correct
71 Correct 1319 ms 160868 KB Output is correct
72 Correct 1345 ms 160832 KB Output is correct
73 Correct 1287 ms 160912 KB Output is correct
74 Correct 1430 ms 160916 KB Output is correct
75 Correct 1330 ms 160840 KB Output is correct
76 Correct 1332 ms 160912 KB Output is correct
77 Correct 1315 ms 160868 KB Output is correct
78 Correct 1339 ms 160860 KB Output is correct
79 Correct 1268 ms 160860 KB Output is correct
80 Correct 1303 ms 160844 KB Output is correct
81 Correct 1319 ms 160956 KB Output is correct
82 Correct 1312 ms 161028 KB Output is correct
83 Correct 1300 ms 160952 KB Output is correct
84 Correct 1384 ms 160960 KB Output is correct
85 Correct 1432 ms 161068 KB Output is correct
86 Correct 1336 ms 161020 KB Output is correct
87 Correct 1357 ms 160932 KB Output is correct
88 Correct 1364 ms 160908 KB Output is correct
89 Correct 1607 ms 160864 KB Output is correct
90 Correct 1459 ms 160852 KB Output is correct
91 Correct 1461 ms 160928 KB Output is correct
92 Correct 1415 ms 160828 KB Output is correct
93 Correct 1439 ms 160952 KB Output is correct
94 Correct 1447 ms 160920 KB Output is correct
95 Correct 1451 ms 160920 KB Output is correct
96 Correct 1425 ms 160836 KB Output is correct
97 Correct 1424 ms 160936 KB Output is correct
98 Correct 1372 ms 160912 KB Output is correct
99 Correct 1407 ms 160836 KB Output is correct
100 Correct 955 ms 140216 KB Output is correct
101 Correct 904 ms 140280 KB Output is correct
102 Correct 883 ms 140308 KB Output is correct
103 Correct 913 ms 140260 KB Output is correct
104 Correct 958 ms 140260 KB Output is correct
105 Correct 1016 ms 161008 KB Output is correct
106 Correct 1056 ms 160940 KB Output is correct
107 Correct 1113 ms 160968 KB Output is correct
108 Correct 1006 ms 160924 KB Output is correct
109 Correct 1010 ms 160956 KB Output is correct
110 Correct 1193 ms 161272 KB Output is correct
111 Correct 1136 ms 161352 KB Output is correct
112 Correct 1122 ms 161332 KB Output is correct
113 Correct 1100 ms 161284 KB Output is correct
114 Correct 1072 ms 161316 KB Output is correct
115 Correct 1128 ms 161264 KB Output is correct
116 Correct 1216 ms 161380 KB Output is correct
117 Correct 1153 ms 161320 KB Output is correct
118 Correct 1231 ms 161408 KB Output is correct
119 Correct 1129 ms 161252 KB Output is correct
120 Correct 1 ms 212 KB Output is correct
121 Correct 1 ms 212 KB Output is correct
122 Correct 1226 ms 160936 KB Output is correct
123 Correct 1483 ms 160968 KB Output is correct
124 Correct 1241 ms 160936 KB Output is correct
125 Correct 1317 ms 160920 KB Output is correct
126 Correct 1429 ms 161024 KB Output is correct
127 Correct 1244 ms 160932 KB Output is correct
128 Correct 1242 ms 161020 KB Output is correct
129 Correct 1163 ms 161028 KB Output is correct
130 Correct 1427 ms 160900 KB Output is correct
131 Correct 1274 ms 161148 KB Output is correct
132 Correct 1226 ms 160920 KB Output is correct
133 Correct 1467 ms 160984 KB Output is correct