Submission #590558

# Submission time Handle Problem Language Result Execution time Memory
590558 2022-07-06T06:36:23 Z 반딧불(#8412) Bulldozer (JOI17_bulldozer) C++17
55 / 100
1075 ms 159696 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);
    }

    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;
    }
};
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{
        return ccw(slope, vector2(0, 0), r.slope) < 0;
    }
};

int n;
vector2 arr[2002];
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());

    ans = max(ans, tree.query());
    for(dat tmp: vec){
        int X = tmp.x, Y = tmp.y;
//        printf("Swap %d %d\n", X, 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);
        ans = max(ans, tree.query());
//        printf("Now Ans: %lld\n", ans);
    }

    printf("%lld", ans);
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:100:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
bulldozer.cpp:102:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |         scanf("%lld %lld %lld", &arr[i].x, &arr[i].y, &arr[i].v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1108 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 2 ms 692 KB Output is correct
5 Correct 3 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 3 ms 692 KB Output is correct
9 Correct 3 ms 692 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 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 788 KB Output is correct
22 Correct 2 ms 692 KB Output is correct
23 Correct 2 ms 692 KB Output is correct
24 Correct 2 ms 692 KB Output is correct
25 Correct 2 ms 788 KB Output is correct
26 Correct 2 ms 692 KB Output is correct
27 Correct 2 ms 788 KB Output is correct
28 Correct 2 ms 692 KB Output is correct
29 Correct 2 ms 692 KB Output is correct
30 Correct 2 ms 820 KB Output is correct
31 Correct 2 ms 692 KB Output is correct
32 Correct 2 ms 788 KB Output is correct
# Verdict Execution time Memory 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 2 ms 692 KB Output is correct
5 Correct 3 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 3 ms 692 KB Output is correct
9 Correct 3 ms 692 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 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 788 KB Output is correct
22 Correct 2 ms 692 KB Output is correct
23 Correct 2 ms 692 KB Output is correct
24 Correct 2 ms 692 KB Output is correct
25 Correct 2 ms 788 KB Output is correct
26 Correct 2 ms 692 KB Output is correct
27 Correct 2 ms 788 KB Output is correct
28 Correct 2 ms 692 KB Output is correct
29 Correct 2 ms 692 KB Output is correct
30 Correct 2 ms 820 KB Output is correct
31 Correct 2 ms 692 KB Output is correct
32 Correct 2 ms 788 KB Output is correct
33 Correct 1006 ms 82772 KB Output is correct
34 Correct 983 ms 82752 KB Output is correct
35 Correct 977 ms 82816 KB Output is correct
36 Correct 988 ms 82648 KB Output is correct
37 Correct 1000 ms 82680 KB Output is correct
38 Correct 977 ms 82652 KB Output is correct
39 Correct 1008 ms 82652 KB Output is correct
40 Correct 998 ms 82756 KB Output is correct
41 Correct 979 ms 82780 KB Output is correct
42 Correct 978 ms 82728 KB Output is correct
43 Correct 968 ms 82700 KB Output is correct
44 Correct 951 ms 82708 KB Output is correct
45 Correct 931 ms 82680 KB Output is correct
46 Correct 1006 ms 82668 KB Output is correct
47 Correct 975 ms 82652 KB Output is correct
48 Correct 1000 ms 82672 KB Output is correct
49 Correct 991 ms 82692 KB Output is correct
50 Correct 1075 ms 82780 KB Output is correct
51 Correct 1068 ms 82724 KB Output is correct
52 Correct 982 ms 82692 KB Output is correct
53 Correct 1010 ms 82712 KB Output is correct
54 Correct 1012 ms 82768 KB Output is correct
# Verdict Execution time Memory 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 2 ms 692 KB Output is correct
5 Correct 3 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 3 ms 692 KB Output is correct
9 Correct 3 ms 692 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 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 788 KB Output is correct
22 Correct 2 ms 692 KB Output is correct
23 Correct 2 ms 692 KB Output is correct
24 Correct 2 ms 692 KB Output is correct
25 Correct 2 ms 788 KB Output is correct
26 Correct 2 ms 692 KB Output is correct
27 Correct 2 ms 788 KB Output is correct
28 Correct 2 ms 692 KB Output is correct
29 Correct 2 ms 692 KB Output is correct
30 Correct 2 ms 820 KB Output is correct
31 Correct 2 ms 692 KB Output is correct
32 Correct 2 ms 788 KB Output is correct
33 Correct 1006 ms 82772 KB Output is correct
34 Correct 983 ms 82752 KB Output is correct
35 Correct 977 ms 82816 KB Output is correct
36 Correct 988 ms 82648 KB Output is correct
37 Correct 1000 ms 82680 KB Output is correct
38 Correct 977 ms 82652 KB Output is correct
39 Correct 1008 ms 82652 KB Output is correct
40 Correct 998 ms 82756 KB Output is correct
41 Correct 979 ms 82780 KB Output is correct
42 Correct 978 ms 82728 KB Output is correct
43 Correct 968 ms 82700 KB Output is correct
44 Correct 951 ms 82708 KB Output is correct
45 Correct 931 ms 82680 KB Output is correct
46 Correct 1006 ms 82668 KB Output is correct
47 Correct 975 ms 82652 KB Output is correct
48 Correct 1000 ms 82672 KB Output is correct
49 Correct 991 ms 82692 KB Output is correct
50 Correct 1075 ms 82780 KB Output is correct
51 Correct 1068 ms 82724 KB Output is correct
52 Correct 982 ms 82692 KB Output is correct
53 Correct 1010 ms 82712 KB Output is correct
54 Correct 1012 ms 82768 KB Output is correct
55 Correct 971 ms 82736 KB Output is correct
56 Correct 974 ms 82712 KB Output is correct
57 Correct 1010 ms 82652 KB Output is correct
58 Correct 1020 ms 82692 KB Output is correct
59 Correct 980 ms 82700 KB Output is correct
60 Correct 1008 ms 82740 KB Output is correct
61 Correct 975 ms 82744 KB Output is correct
62 Correct 1012 ms 82668 KB Output is correct
63 Correct 996 ms 82780 KB Output is correct
64 Correct 976 ms 82724 KB Output is correct
65 Runtime error 595 ms 159696 KB Execution killed with signal 6
66 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1108 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -