답안 #197701

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197701 2020-01-22T11:19:34 Z ksmzzang2003 Bulldozer (JOI17_bulldozer) C++14
80 / 100
2000 ms 67036 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld ;
typedef pair <ll,ll> pll ;
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define MAXN 5003
const ll llinf = 0x3f3f3f3f3f3f3f3f;
struct po {
    ll x,y;
    ll co;
    bool operator <(po &r) {
        return pll(x,y) < pll(r.x,r.y);
    }
} arr[MAXN];

struct line {
    ll i,j;
    long double a;
    line(int i,int j,ld a):i(i),j(j),a(a) {}
    bool operator<(line &r) {
        if(a!=r.a) return a>r.a;
        return pll(i,j) < pll(r.i,r.j);
    }
};
vector <line>  larr;
ll N;
struct node {
    ll lsum,rsum,sum,ans;
    node() {
        lsum = rsum = sum = ans  =0 ;
    }
    node(ll l,ll r,ll s,ll a) {
        lsum  = l;
        rsum =r;
        sum =s ;
        ans = a;
    }
};
struct seg {
    node tree[5003*4];
    node merge(node l,node r) {
        node ret;
        ret.lsum = max(l.lsum,l.sum + r.lsum);
        ret.rsum = max(r.rsum,l.rsum + r.sum);
        ret.sum  = l.sum + r.sum;
        ret.ans = max({l.ans,r.ans,ret.sum,l.rsum + r.lsum});
        return ret;
    }
    node query(ll nodE,ll ns,ll ne,ll s,ll e) {
        if(e<ns || ne <s )
            return node(0,0,0,0);
        if(s<=ns &&ne <=e)
            return tree[nodE];
        return merge(query(nodE*2,ns,ns + ne >>1,s,e),query(nodE*2+1,(ns+ne>>1) + 1,ne,s,e));
    }
    void update(ll nodE,ll ns,ll ne,ll id,node k) {
        if(ne < id || id < ns)
            return;
        if(ns == ne) {
            tree[nodE] = k;
            return ;
        }
        update(nodE*2,ns,(ns+ne)/2,id,k);
        update(nodE*2+1,(ns+ne)/2+1,ne,id,k);
        tree[nodE] = merge(tree[nodE*2],tree[nodE*2+1]);
    }
} SEG;
int ind[5003];
int main() {
    scanf("%lld",&N);
    for(ll i=1; i<=N; i++)
        scanf("%lld %lld %lld", &arr[i].x,&arr[i].y,&arr[i].co);
    sort(arr+1,arr+1+N);
    for(ll i=1; i<=N; i++) {
        for(ll j=i+1; j<=N; j++) {
            long double deltax = (ld)arr[i].x - arr[j].x;
            long double deltay = (ld)arr[i].y - arr[j].y;
            if(deltax==0) deltax =1e-18 , deltay =1e18;
            larr.eb(i,j,deltay/deltax);
        }
    }
    sort(larr.begin(),larr.end());
    for(ll i=1; i<=N; i++) {
        ll C = max(0LL,arr[i].co);
        SEG.update(1,1,N,i,node(C,C,arr[i].co,C));
    }
    ll res = SEG.query(1,1,N,1,N).ans;
    for(int i=1; i<=N; i++)
        ind[i] =i ;
    for(int i=0; i<larr.size(); i++) {
        int e;
        for(int j=i; j<larr.size(); j++) {
            if(larr[i].a == larr[j].a)
                e = j;
            else
                break;
        }
        for(int j = i ; j<=e; j++) {
            auto it = larr[j];
            ll l = it.i, r = it.j ;
            node x = SEG.query(1,1,N,ind[l],ind[l]);
            node y = SEG.query(1,1,N,ind[r],ind[r]);
            SEG.update(1,1,N,ind[r],x);
            SEG.update(1,1,N,ind[l],y);
            swap(ind[l],ind[r]);
        }
        res = max(res,SEG.query(1,1,N,1,N).ans);
        i=e;
    }
    printf("%lld",res);
}

Compilation message

bulldozer.cpp: In member function 'node seg::query(ll, ll, ll, ll, ll)':
bulldozer.cpp:57:41: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         return merge(query(nodE*2,ns,ns + ne >>1,s,e),query(nodE*2+1,(ns+ne>>1) + 1,ne,s,e));
                                      ~~~^~~~
bulldozer.cpp:57:73: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         return merge(query(nodE*2,ns,ns + ne >>1,s,e),query(nodE*2+1,(ns+ne>>1) + 1,ne,s,e));
                                                                       ~~^~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:93:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<larr.size(); i++) {
                  ~^~~~~~~~~~~~
bulldozer.cpp:95:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=i; j<larr.size(); j++) {
                      ~^~~~~~~~~~~~
bulldozer.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&N);
     ~~~~~^~~~~~~~~~~
bulldozer.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld %lld", &arr[i].x,&arr[i].y,&arr[i].co);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bulldozer.cpp:94:13: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
         int e;
             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1400 KB Output is correct
2 Correct 5 ms 1400 KB Output is correct
3 Correct 5 ms 1400 KB Output is correct
4 Correct 5 ms 1400 KB Output is correct
5 Correct 5 ms 1444 KB Output is correct
6 Correct 5 ms 1272 KB Output is correct
7 Correct 5 ms 1272 KB Output is correct
8 Correct 5 ms 1272 KB Output is correct
9 Correct 6 ms 1400 KB Output is correct
10 Correct 5 ms 1400 KB Output is correct
11 Correct 3 ms 1016 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1016 KB Output is correct
14 Correct 3 ms 1016 KB Output is correct
15 Correct 3 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1272 KB Output is correct
2 Correct 6 ms 1400 KB Output is correct
3 Correct 5 ms 1272 KB Output is correct
4 Correct 5 ms 1272 KB Output is correct
5 Correct 5 ms 1400 KB Output is correct
6 Correct 5 ms 1400 KB Output is correct
7 Correct 5 ms 1272 KB Output is correct
8 Correct 5 ms 1400 KB Output is correct
9 Correct 6 ms 1400 KB Output is correct
10 Correct 5 ms 1272 KB Output is correct
11 Correct 2 ms 1016 KB Output is correct
12 Correct 2 ms 892 KB Output is correct
13 Correct 2 ms 1016 KB Output is correct
14 Correct 2 ms 1016 KB Output is correct
15 Correct 3 ms 1016 KB Output is correct
16 Correct 2 ms 1016 KB Output is correct
17 Correct 3 ms 1016 KB Output is correct
18 Correct 2 ms 888 KB Output is correct
19 Correct 2 ms 888 KB Output is correct
20 Correct 2 ms 888 KB Output is correct
21 Correct 5 ms 1272 KB Output is correct
22 Correct 5 ms 1400 KB Output is correct
23 Correct 6 ms 1272 KB Output is correct
24 Correct 5 ms 1272 KB Output is correct
25 Correct 6 ms 1272 KB Output is correct
26 Correct 6 ms 1400 KB Output is correct
27 Correct 5 ms 1272 KB Output is correct
28 Correct 5 ms 1276 KB Output is correct
29 Correct 6 ms 1272 KB Output is correct
30 Correct 5 ms 1400 KB Output is correct
31 Correct 5 ms 1400 KB Output is correct
32 Correct 6 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1272 KB Output is correct
2 Correct 6 ms 1400 KB Output is correct
3 Correct 5 ms 1272 KB Output is correct
4 Correct 5 ms 1272 KB Output is correct
5 Correct 5 ms 1400 KB Output is correct
6 Correct 5 ms 1400 KB Output is correct
7 Correct 5 ms 1272 KB Output is correct
8 Correct 5 ms 1400 KB Output is correct
9 Correct 6 ms 1400 KB Output is correct
10 Correct 5 ms 1272 KB Output is correct
11 Correct 2 ms 1016 KB Output is correct
12 Correct 2 ms 892 KB Output is correct
13 Correct 2 ms 1016 KB Output is correct
14 Correct 2 ms 1016 KB Output is correct
15 Correct 3 ms 1016 KB Output is correct
16 Correct 2 ms 1016 KB Output is correct
17 Correct 3 ms 1016 KB Output is correct
18 Correct 2 ms 888 KB Output is correct
19 Correct 2 ms 888 KB Output is correct
20 Correct 2 ms 888 KB Output is correct
21 Correct 5 ms 1272 KB Output is correct
22 Correct 5 ms 1400 KB Output is correct
23 Correct 6 ms 1272 KB Output is correct
24 Correct 5 ms 1272 KB Output is correct
25 Correct 6 ms 1272 KB Output is correct
26 Correct 6 ms 1400 KB Output is correct
27 Correct 5 ms 1272 KB Output is correct
28 Correct 5 ms 1276 KB Output is correct
29 Correct 6 ms 1272 KB Output is correct
30 Correct 5 ms 1400 KB Output is correct
31 Correct 5 ms 1400 KB Output is correct
32 Correct 6 ms 1400 KB Output is correct
33 Correct 1988 ms 66748 KB Output is correct
34 Correct 1973 ms 66892 KB Output is correct
35 Correct 1976 ms 66840 KB Output is correct
36 Correct 1973 ms 66840 KB Output is correct
37 Correct 1972 ms 66928 KB Output is correct
38 Correct 1971 ms 66968 KB Output is correct
39 Correct 1962 ms 66840 KB Output is correct
40 Correct 1972 ms 66840 KB Output is correct
41 Correct 1963 ms 66840 KB Output is correct
42 Correct 1968 ms 66844 KB Output is correct
43 Correct 1971 ms 66844 KB Output is correct
44 Correct 1947 ms 66832 KB Output is correct
45 Correct 1952 ms 66840 KB Output is correct
46 Correct 1974 ms 66840 KB Output is correct
47 Correct 1959 ms 66840 KB Output is correct
48 Correct 1984 ms 66840 KB Output is correct
49 Correct 1950 ms 66840 KB Output is correct
50 Correct 1956 ms 66968 KB Output is correct
51 Correct 1972 ms 67036 KB Output is correct
52 Correct 1956 ms 66840 KB Output is correct
53 Correct 1954 ms 66840 KB Output is correct
54 Correct 1983 ms 66840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1272 KB Output is correct
2 Correct 6 ms 1400 KB Output is correct
3 Correct 5 ms 1272 KB Output is correct
4 Correct 5 ms 1272 KB Output is correct
5 Correct 5 ms 1400 KB Output is correct
6 Correct 5 ms 1400 KB Output is correct
7 Correct 5 ms 1272 KB Output is correct
8 Correct 5 ms 1400 KB Output is correct
9 Correct 6 ms 1400 KB Output is correct
10 Correct 5 ms 1272 KB Output is correct
11 Correct 2 ms 1016 KB Output is correct
12 Correct 2 ms 892 KB Output is correct
13 Correct 2 ms 1016 KB Output is correct
14 Correct 2 ms 1016 KB Output is correct
15 Correct 3 ms 1016 KB Output is correct
16 Correct 2 ms 1016 KB Output is correct
17 Correct 3 ms 1016 KB Output is correct
18 Correct 2 ms 888 KB Output is correct
19 Correct 2 ms 888 KB Output is correct
20 Correct 2 ms 888 KB Output is correct
21 Correct 5 ms 1272 KB Output is correct
22 Correct 5 ms 1400 KB Output is correct
23 Correct 6 ms 1272 KB Output is correct
24 Correct 5 ms 1272 KB Output is correct
25 Correct 6 ms 1272 KB Output is correct
26 Correct 6 ms 1400 KB Output is correct
27 Correct 5 ms 1272 KB Output is correct
28 Correct 5 ms 1276 KB Output is correct
29 Correct 6 ms 1272 KB Output is correct
30 Correct 5 ms 1400 KB Output is correct
31 Correct 5 ms 1400 KB Output is correct
32 Correct 6 ms 1400 KB Output is correct
33 Correct 1988 ms 66748 KB Output is correct
34 Correct 1973 ms 66892 KB Output is correct
35 Correct 1976 ms 66840 KB Output is correct
36 Correct 1973 ms 66840 KB Output is correct
37 Correct 1972 ms 66928 KB Output is correct
38 Correct 1971 ms 66968 KB Output is correct
39 Correct 1962 ms 66840 KB Output is correct
40 Correct 1972 ms 66840 KB Output is correct
41 Correct 1963 ms 66840 KB Output is correct
42 Correct 1968 ms 66844 KB Output is correct
43 Correct 1971 ms 66844 KB Output is correct
44 Correct 1947 ms 66832 KB Output is correct
45 Correct 1952 ms 66840 KB Output is correct
46 Correct 1974 ms 66840 KB Output is correct
47 Correct 1959 ms 66840 KB Output is correct
48 Correct 1984 ms 66840 KB Output is correct
49 Correct 1950 ms 66840 KB Output is correct
50 Correct 1956 ms 66968 KB Output is correct
51 Correct 1972 ms 67036 KB Output is correct
52 Correct 1956 ms 66840 KB Output is correct
53 Correct 1954 ms 66840 KB Output is correct
54 Correct 1983 ms 66840 KB Output is correct
55 Correct 1969 ms 66688 KB Output is correct
56 Correct 1965 ms 66840 KB Output is correct
57 Correct 1972 ms 66840 KB Output is correct
58 Correct 1996 ms 66840 KB Output is correct
59 Correct 1984 ms 66840 KB Output is correct
60 Correct 1975 ms 66840 KB Output is correct
61 Correct 1975 ms 66840 KB Output is correct
62 Correct 1982 ms 66968 KB Output is correct
63 Correct 1987 ms 66968 KB Output is correct
64 Correct 1991 ms 66816 KB Output is correct
65 Correct 1965 ms 66840 KB Output is correct
66 Correct 1971 ms 66840 KB Output is correct
67 Correct 1962 ms 66840 KB Output is correct
68 Correct 1988 ms 66860 KB Output is correct
69 Correct 1964 ms 66840 KB Output is correct
70 Correct 1972 ms 66840 KB Output is correct
71 Correct 1969 ms 66840 KB Output is correct
72 Correct 1970 ms 66840 KB Output is correct
73 Correct 1971 ms 66972 KB Output is correct
74 Correct 1963 ms 67004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1400 KB Output is correct
2 Correct 5 ms 1400 KB Output is correct
3 Correct 5 ms 1400 KB Output is correct
4 Correct 5 ms 1400 KB Output is correct
5 Correct 5 ms 1444 KB Output is correct
6 Correct 5 ms 1272 KB Output is correct
7 Correct 5 ms 1272 KB Output is correct
8 Correct 5 ms 1272 KB Output is correct
9 Correct 6 ms 1400 KB Output is correct
10 Correct 5 ms 1400 KB Output is correct
11 Correct 3 ms 1016 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1016 KB Output is correct
14 Correct 3 ms 1016 KB Output is correct
15 Correct 3 ms 1016 KB Output is correct
16 Correct 5 ms 1272 KB Output is correct
17 Correct 6 ms 1400 KB Output is correct
18 Correct 5 ms 1272 KB Output is correct
19 Correct 5 ms 1272 KB Output is correct
20 Correct 5 ms 1400 KB Output is correct
21 Correct 5 ms 1400 KB Output is correct
22 Correct 5 ms 1272 KB Output is correct
23 Correct 5 ms 1400 KB Output is correct
24 Correct 6 ms 1400 KB Output is correct
25 Correct 5 ms 1272 KB Output is correct
26 Correct 2 ms 1016 KB Output is correct
27 Correct 2 ms 892 KB Output is correct
28 Correct 2 ms 1016 KB Output is correct
29 Correct 2 ms 1016 KB Output is correct
30 Correct 3 ms 1016 KB Output is correct
31 Correct 2 ms 1016 KB Output is correct
32 Correct 3 ms 1016 KB Output is correct
33 Correct 2 ms 888 KB Output is correct
34 Correct 2 ms 888 KB Output is correct
35 Correct 2 ms 888 KB Output is correct
36 Correct 5 ms 1272 KB Output is correct
37 Correct 5 ms 1400 KB Output is correct
38 Correct 6 ms 1272 KB Output is correct
39 Correct 5 ms 1272 KB Output is correct
40 Correct 6 ms 1272 KB Output is correct
41 Correct 6 ms 1400 KB Output is correct
42 Correct 5 ms 1272 KB Output is correct
43 Correct 5 ms 1276 KB Output is correct
44 Correct 6 ms 1272 KB Output is correct
45 Correct 5 ms 1400 KB Output is correct
46 Correct 5 ms 1400 KB Output is correct
47 Correct 6 ms 1400 KB Output is correct
48 Correct 1988 ms 66748 KB Output is correct
49 Correct 1973 ms 66892 KB Output is correct
50 Correct 1976 ms 66840 KB Output is correct
51 Correct 1973 ms 66840 KB Output is correct
52 Correct 1972 ms 66928 KB Output is correct
53 Correct 1971 ms 66968 KB Output is correct
54 Correct 1962 ms 66840 KB Output is correct
55 Correct 1972 ms 66840 KB Output is correct
56 Correct 1963 ms 66840 KB Output is correct
57 Correct 1968 ms 66844 KB Output is correct
58 Correct 1971 ms 66844 KB Output is correct
59 Correct 1947 ms 66832 KB Output is correct
60 Correct 1952 ms 66840 KB Output is correct
61 Correct 1974 ms 66840 KB Output is correct
62 Correct 1959 ms 66840 KB Output is correct
63 Correct 1984 ms 66840 KB Output is correct
64 Correct 1950 ms 66840 KB Output is correct
65 Correct 1956 ms 66968 KB Output is correct
66 Correct 1972 ms 67036 KB Output is correct
67 Correct 1956 ms 66840 KB Output is correct
68 Correct 1954 ms 66840 KB Output is correct
69 Correct 1983 ms 66840 KB Output is correct
70 Correct 1969 ms 66688 KB Output is correct
71 Correct 1965 ms 66840 KB Output is correct
72 Correct 1972 ms 66840 KB Output is correct
73 Correct 1996 ms 66840 KB Output is correct
74 Correct 1984 ms 66840 KB Output is correct
75 Correct 1975 ms 66840 KB Output is correct
76 Correct 1975 ms 66840 KB Output is correct
77 Correct 1982 ms 66968 KB Output is correct
78 Correct 1987 ms 66968 KB Output is correct
79 Correct 1991 ms 66816 KB Output is correct
80 Correct 1965 ms 66840 KB Output is correct
81 Correct 1971 ms 66840 KB Output is correct
82 Correct 1962 ms 66840 KB Output is correct
83 Correct 1988 ms 66860 KB Output is correct
84 Correct 1964 ms 66840 KB Output is correct
85 Correct 1972 ms 66840 KB Output is correct
86 Correct 1969 ms 66840 KB Output is correct
87 Correct 1970 ms 66840 KB Output is correct
88 Correct 1971 ms 66972 KB Output is correct
89 Correct 1963 ms 67004 KB Output is correct
90 Correct 1991 ms 66808 KB Output is correct
91 Correct 1979 ms 66932 KB Output is correct
92 Correct 1973 ms 66840 KB Output is correct
93 Correct 1968 ms 67012 KB Output is correct
94 Correct 1964 ms 66840 KB Output is correct
95 Correct 1996 ms 66844 KB Output is correct
96 Execution timed out 2005 ms 66888 KB Time limit exceeded
97 Halted 0 ms 0 KB -