Submission #590589

# Submission time Handle Problem Language Result Execution time Memory
590589 2022-07-06T07:10:53 Z 반딧불(#8412) Bulldozer (JOI17_bulldozer) C++17
80 / 100
1402 ms 161168 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 (1000000001, -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);
        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:109:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
bulldozer.cpp:111:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |         scanf("%lld %lld %lld", &arr[i].x, &arr[i].y, &arr[i].v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 692 KB Output is correct
2 Correct 3 ms 692 KB Output is correct
3 Correct 3 ms 692 KB Output is correct
4 Correct 2 ms 692 KB Output is correct
5 Correct 2 ms 692 KB Output is correct
6 Correct 3 ms 692 KB Output is correct
7 Correct 2 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 792 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 304 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory 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 3 ms 912 KB Output is correct
5 Correct 3 ms 912 KB Output is correct
6 Correct 3 ms 912 KB Output is correct
7 Correct 3 ms 912 KB Output is correct
8 Correct 3 ms 912 KB Output is correct
9 Correct 3 ms 912 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 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 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 2 ms 912 KB Output is correct
25 Correct 2 ms 912 KB Output is correct
26 Correct 3 ms 912 KB Output is correct
27 Correct 3 ms 912 KB Output is correct
28 Correct 3 ms 912 KB Output is correct
29 Correct 3 ms 912 KB Output is correct
30 Correct 2 ms 912 KB Output is correct
31 Correct 3 ms 912 KB Output is correct
32 Correct 3 ms 912 KB Output is correct
# Verdict Execution time Memory 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 3 ms 912 KB Output is correct
5 Correct 3 ms 912 KB Output is correct
6 Correct 3 ms 912 KB Output is correct
7 Correct 3 ms 912 KB Output is correct
8 Correct 3 ms 912 KB Output is correct
9 Correct 3 ms 912 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 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 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 2 ms 912 KB Output is correct
25 Correct 2 ms 912 KB Output is correct
26 Correct 3 ms 912 KB Output is correct
27 Correct 3 ms 912 KB Output is correct
28 Correct 3 ms 912 KB Output is correct
29 Correct 3 ms 912 KB Output is correct
30 Correct 2 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 1402 ms 160900 KB Output is correct
34 Correct 1295 ms 160952 KB Output is correct
35 Correct 1323 ms 161080 KB Output is correct
36 Correct 1278 ms 160876 KB Output is correct
37 Correct 1300 ms 160828 KB Output is correct
38 Correct 1259 ms 160868 KB Output is correct
39 Correct 1272 ms 160956 KB Output is correct
40 Correct 1282 ms 160828 KB Output is correct
41 Correct 1332 ms 160956 KB Output is correct
42 Correct 1359 ms 160956 KB Output is correct
43 Correct 1355 ms 160956 KB Output is correct
44 Correct 1320 ms 160836 KB Output is correct
45 Correct 1343 ms 160952 KB Output is correct
46 Correct 1380 ms 160832 KB Output is correct
47 Correct 1337 ms 160844 KB Output is correct
48 Correct 1260 ms 160968 KB Output is correct
49 Correct 1275 ms 160988 KB Output is correct
50 Correct 1240 ms 161012 KB Output is correct
51 Correct 1238 ms 160960 KB Output is correct
52 Correct 1266 ms 160828 KB Output is correct
53 Correct 1262 ms 160924 KB Output is correct
54 Correct 1230 ms 160952 KB Output is correct
# Verdict Execution time Memory 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 3 ms 912 KB Output is correct
5 Correct 3 ms 912 KB Output is correct
6 Correct 3 ms 912 KB Output is correct
7 Correct 3 ms 912 KB Output is correct
8 Correct 3 ms 912 KB Output is correct
9 Correct 3 ms 912 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 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 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 2 ms 912 KB Output is correct
25 Correct 2 ms 912 KB Output is correct
26 Correct 3 ms 912 KB Output is correct
27 Correct 3 ms 912 KB Output is correct
28 Correct 3 ms 912 KB Output is correct
29 Correct 3 ms 912 KB Output is correct
30 Correct 2 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 1402 ms 160900 KB Output is correct
34 Correct 1295 ms 160952 KB Output is correct
35 Correct 1323 ms 161080 KB Output is correct
36 Correct 1278 ms 160876 KB Output is correct
37 Correct 1300 ms 160828 KB Output is correct
38 Correct 1259 ms 160868 KB Output is correct
39 Correct 1272 ms 160956 KB Output is correct
40 Correct 1282 ms 160828 KB Output is correct
41 Correct 1332 ms 160956 KB Output is correct
42 Correct 1359 ms 160956 KB Output is correct
43 Correct 1355 ms 160956 KB Output is correct
44 Correct 1320 ms 160836 KB Output is correct
45 Correct 1343 ms 160952 KB Output is correct
46 Correct 1380 ms 160832 KB Output is correct
47 Correct 1337 ms 160844 KB Output is correct
48 Correct 1260 ms 160968 KB Output is correct
49 Correct 1275 ms 160988 KB Output is correct
50 Correct 1240 ms 161012 KB Output is correct
51 Correct 1238 ms 160960 KB Output is correct
52 Correct 1266 ms 160828 KB Output is correct
53 Correct 1262 ms 160924 KB Output is correct
54 Correct 1230 ms 160952 KB Output is correct
55 Correct 1329 ms 160964 KB Output is correct
56 Correct 1302 ms 160864 KB Output is correct
57 Correct 1308 ms 160832 KB Output is correct
58 Correct 1274 ms 160836 KB Output is correct
59 Correct 1262 ms 160836 KB Output is correct
60 Correct 1280 ms 160884 KB Output is correct
61 Correct 1270 ms 161008 KB Output is correct
62 Correct 1281 ms 160992 KB Output is correct
63 Correct 1256 ms 160928 KB Output is correct
64 Correct 1288 ms 160832 KB Output is correct
65 Correct 1276 ms 160856 KB Output is correct
66 Correct 1311 ms 160948 KB Output is correct
67 Correct 1270 ms 160944 KB Output is correct
68 Correct 1305 ms 160896 KB Output is correct
69 Correct 1290 ms 161000 KB Output is correct
70 Correct 1276 ms 161000 KB Output is correct
71 Correct 1308 ms 161000 KB Output is correct
72 Correct 1269 ms 161056 KB Output is correct
73 Correct 1280 ms 160900 KB Output is correct
74 Correct 1245 ms 161072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 692 KB Output is correct
2 Correct 3 ms 692 KB Output is correct
3 Correct 3 ms 692 KB Output is correct
4 Correct 2 ms 692 KB Output is correct
5 Correct 2 ms 692 KB Output is correct
6 Correct 3 ms 692 KB Output is correct
7 Correct 2 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 792 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 304 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 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 3 ms 912 KB Output is correct
20 Correct 3 ms 912 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 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 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 2 ms 912 KB Output is correct
40 Correct 2 ms 912 KB Output is correct
41 Correct 3 ms 912 KB Output is correct
42 Correct 3 ms 912 KB Output is correct
43 Correct 3 ms 912 KB Output is correct
44 Correct 3 ms 912 KB Output is correct
45 Correct 2 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 1402 ms 160900 KB Output is correct
49 Correct 1295 ms 160952 KB Output is correct
50 Correct 1323 ms 161080 KB Output is correct
51 Correct 1278 ms 160876 KB Output is correct
52 Correct 1300 ms 160828 KB Output is correct
53 Correct 1259 ms 160868 KB Output is correct
54 Correct 1272 ms 160956 KB Output is correct
55 Correct 1282 ms 160828 KB Output is correct
56 Correct 1332 ms 160956 KB Output is correct
57 Correct 1359 ms 160956 KB Output is correct
58 Correct 1355 ms 160956 KB Output is correct
59 Correct 1320 ms 160836 KB Output is correct
60 Correct 1343 ms 160952 KB Output is correct
61 Correct 1380 ms 160832 KB Output is correct
62 Correct 1337 ms 160844 KB Output is correct
63 Correct 1260 ms 160968 KB Output is correct
64 Correct 1275 ms 160988 KB Output is correct
65 Correct 1240 ms 161012 KB Output is correct
66 Correct 1238 ms 160960 KB Output is correct
67 Correct 1266 ms 160828 KB Output is correct
68 Correct 1262 ms 160924 KB Output is correct
69 Correct 1230 ms 160952 KB Output is correct
70 Correct 1329 ms 160964 KB Output is correct
71 Correct 1302 ms 160864 KB Output is correct
72 Correct 1308 ms 160832 KB Output is correct
73 Correct 1274 ms 160836 KB Output is correct
74 Correct 1262 ms 160836 KB Output is correct
75 Correct 1280 ms 160884 KB Output is correct
76 Correct 1270 ms 161008 KB Output is correct
77 Correct 1281 ms 160992 KB Output is correct
78 Correct 1256 ms 160928 KB Output is correct
79 Correct 1288 ms 160832 KB Output is correct
80 Correct 1276 ms 160856 KB Output is correct
81 Correct 1311 ms 160948 KB Output is correct
82 Correct 1270 ms 160944 KB Output is correct
83 Correct 1305 ms 160896 KB Output is correct
84 Correct 1290 ms 161000 KB Output is correct
85 Correct 1276 ms 161000 KB Output is correct
86 Correct 1308 ms 161000 KB Output is correct
87 Correct 1269 ms 161056 KB Output is correct
88 Correct 1280 ms 160900 KB Output is correct
89 Correct 1245 ms 161072 KB Output is correct
90 Correct 1274 ms 160952 KB Output is correct
91 Correct 1276 ms 160932 KB Output is correct
92 Correct 1258 ms 160944 KB Output is correct
93 Correct 1296 ms 161028 KB Output is correct
94 Correct 1326 ms 160924 KB Output is correct
95 Correct 1277 ms 160900 KB Output is correct
96 Correct 1325 ms 161168 KB Output is correct
97 Correct 1269 ms 160932 KB Output is correct
98 Correct 1307 ms 161076 KB Output is correct
99 Correct 1288 ms 161004 KB Output is correct
100 Incorrect 1049 ms 140356 KB Output isn't correct
101 Halted 0 ms 0 KB -