답안 #154609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154609 2019-09-23T10:05:00 Z Mercenary Bulldozer (JOI17_bulldozer) C++14
100 / 100
987 ms 47608 KB
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;

const int maxn = 2e3 + 5;

int n;
struct point{
    int x , y , c;
}a[maxn];
struct line{
    int x , y , ii , jj;
};
struct node{
    ll res , pre , sum , suf;
    node(){};
    node(ll sum , ll res , ll pre , ll suf):sum(sum) , res(res) , pre(pre) , suf(suf){}
    node operator + (const node & other){
        return node(
                sum + other.sum,
                max({res , other.res , suf + other.pre}),
                max({pre , sum + other.pre}),
                max({other.suf , other.sum + suf})
                    );
    }
}s[maxn * 4];

void Build(int x , int l , int r){
    if(l == r){
        s[x] = node(a[l].c , a[l].c , a[l].c , a[l].c);
        return;
    }
    int mid = l + r >> 1;
    Build(x * 2 , l , mid);
    Build(x * 2 + 1 , mid + 1 , r);
    s[x] = s[x * 2] + s[x * 2 + 1];
}

void update(int x , int l , int r , int pos , int val){
    if(l == r){
        s[x] = node(val , val , val ,val);
        return;
    }
    int mid = l + r >> 1;
    if(mid >= pos)update(x * 2 , l , mid , pos , val);
    else update(x * 2 + 1 , mid + 1 , r , pos , val);
    s[x] = s[x * 2] + s[x * 2 + 1];
}
int cur[maxn];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    if(fopen(taskname".INP","r")){
        freopen(taskname".INP", "r",stdin);
        freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n ; ++i){
        cin >> a[i].x >> a[i].y >> a[i].c;
        cur[i] = i;
    }
    sort(a + 1 , a + n + 1 , [&](const point & x , const point & y){
            if(x.x == y.x)return x.y < y.y;
            return x.x < y.x;
         });
    vector<line> v;
    v.reserve(n * (n - 1) / 2);
    for(int i = 1 ; i <= n ; ++i){
        for(int j = i + 1 ; j <= n ; ++j){
            v.pb({a[i].x - a[j].x , a[i].y - a[j].y , i , j});
        }
    }
    stable_sort(v.begin(),v.end(),[&](const line & a , const line & b){
            return (ll)a.x * b.y - (ll)a.y * b.x > 0;
                });
    int j = 0;
    ll ans = 0;
    Build(1 , 1 , n);
    ans = max(0ll , s[1].res);
    for(int i = 0 ; i < (int)v.size() ; ){
        while(j < (int)v.size() && (ll)v[i].x * v[j].y == (ll)v[i].y * v[j].x){
            swap(cur[v[j].ii] , cur[v[j].jj]);
            update(1 , 1 , n , cur[v[j].ii] , a[v[j].ii].c);
            update(1 , 1 , n , cur[v[j].jj] , a[v[j].jj].c);
            ++j;
        }
        ans = max(ans , s[1].res);
        i = j;
    }
    cout << ans;
}

Compilation message

bulldozer.cpp: In constructor 'node::node(ll, ll, ll, ll)':
bulldozer.cpp:22:20: warning: 'node::sum' will be initialized after [-Wreorder]
     ll res , pre , sum , suf;
                    ^~~
bulldozer.cpp:22:8: warning:   'll node::res' [-Wreorder]
     ll res , pre , sum , suf;
        ^~~
bulldozer.cpp:24:5: warning:   when initialized here [-Wreorder]
     node(ll sum , ll res , ll pre , ll suf):sum(sum) , res(res) , pre(pre) , suf(suf){}
     ^~~~
bulldozer.cpp: In function 'void Build(int, int, int)':
bulldozer.cpp:40:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
bulldozer.cpp: In function 'void update(int, int, int, int, int)':
bulldozer.cpp:51:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(taskname".INP", "r",stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
bulldozer.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(taskname".OUT", "w",stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 476 KB Output is correct
11 Correct 2 ms 420 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 380 KB Output is correct
21 Correct 4 ms 508 KB Output is correct
22 Correct 4 ms 504 KB Output is correct
23 Correct 3 ms 508 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 476 KB Output is correct
11 Correct 2 ms 420 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 380 KB Output is correct
21 Correct 4 ms 508 KB Output is correct
22 Correct 4 ms 504 KB Output is correct
23 Correct 3 ms 508 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 908 ms 47480 KB Output is correct
34 Correct 881 ms 47352 KB Output is correct
35 Correct 908 ms 47480 KB Output is correct
36 Correct 881 ms 47608 KB Output is correct
37 Correct 881 ms 47424 KB Output is correct
38 Correct 897 ms 47480 KB Output is correct
39 Correct 885 ms 47480 KB Output is correct
40 Correct 884 ms 47436 KB Output is correct
41 Correct 886 ms 47480 KB Output is correct
42 Correct 885 ms 47444 KB Output is correct
43 Correct 902 ms 47352 KB Output is correct
44 Correct 899 ms 47484 KB Output is correct
45 Correct 951 ms 47436 KB Output is correct
46 Correct 947 ms 47480 KB Output is correct
47 Correct 873 ms 47352 KB Output is correct
48 Correct 869 ms 47492 KB Output is correct
49 Correct 871 ms 47480 KB Output is correct
50 Correct 870 ms 47484 KB Output is correct
51 Correct 903 ms 47480 KB Output is correct
52 Correct 881 ms 47436 KB Output is correct
53 Correct 871 ms 47356 KB Output is correct
54 Correct 884 ms 47480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 476 KB Output is correct
11 Correct 2 ms 420 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 380 KB Output is correct
21 Correct 4 ms 508 KB Output is correct
22 Correct 4 ms 504 KB Output is correct
23 Correct 3 ms 508 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 908 ms 47480 KB Output is correct
34 Correct 881 ms 47352 KB Output is correct
35 Correct 908 ms 47480 KB Output is correct
36 Correct 881 ms 47608 KB Output is correct
37 Correct 881 ms 47424 KB Output is correct
38 Correct 897 ms 47480 KB Output is correct
39 Correct 885 ms 47480 KB Output is correct
40 Correct 884 ms 47436 KB Output is correct
41 Correct 886 ms 47480 KB Output is correct
42 Correct 885 ms 47444 KB Output is correct
43 Correct 902 ms 47352 KB Output is correct
44 Correct 899 ms 47484 KB Output is correct
45 Correct 951 ms 47436 KB Output is correct
46 Correct 947 ms 47480 KB Output is correct
47 Correct 873 ms 47352 KB Output is correct
48 Correct 869 ms 47492 KB Output is correct
49 Correct 871 ms 47480 KB Output is correct
50 Correct 870 ms 47484 KB Output is correct
51 Correct 903 ms 47480 KB Output is correct
52 Correct 881 ms 47436 KB Output is correct
53 Correct 871 ms 47356 KB Output is correct
54 Correct 884 ms 47480 KB Output is correct
55 Correct 898 ms 47408 KB Output is correct
56 Correct 883 ms 47352 KB Output is correct
57 Correct 888 ms 47352 KB Output is correct
58 Correct 882 ms 47352 KB Output is correct
59 Correct 882 ms 47444 KB Output is correct
60 Correct 890 ms 47452 KB Output is correct
61 Correct 881 ms 47552 KB Output is correct
62 Correct 881 ms 47480 KB Output is correct
63 Correct 888 ms 47400 KB Output is correct
64 Correct 881 ms 47480 KB Output is correct
65 Correct 898 ms 47432 KB Output is correct
66 Correct 883 ms 47480 KB Output is correct
67 Correct 881 ms 47504 KB Output is correct
68 Correct 939 ms 47352 KB Output is correct
69 Correct 941 ms 47480 KB Output is correct
70 Correct 878 ms 47580 KB Output is correct
71 Correct 922 ms 47476 KB Output is correct
72 Correct 937 ms 47480 KB Output is correct
73 Correct 883 ms 47352 KB Output is correct
74 Correct 884 ms 47352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 4 ms 504 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 4 ms 504 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 504 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 476 KB Output is correct
26 Correct 2 ms 420 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 3 ms 380 KB Output is correct
36 Correct 4 ms 508 KB Output is correct
37 Correct 4 ms 504 KB Output is correct
38 Correct 3 ms 508 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 4 ms 504 KB Output is correct
42 Correct 3 ms 504 KB Output is correct
43 Correct 4 ms 504 KB Output is correct
44 Correct 4 ms 504 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
46 Correct 3 ms 504 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 908 ms 47480 KB Output is correct
49 Correct 881 ms 47352 KB Output is correct
50 Correct 908 ms 47480 KB Output is correct
51 Correct 881 ms 47608 KB Output is correct
52 Correct 881 ms 47424 KB Output is correct
53 Correct 897 ms 47480 KB Output is correct
54 Correct 885 ms 47480 KB Output is correct
55 Correct 884 ms 47436 KB Output is correct
56 Correct 886 ms 47480 KB Output is correct
57 Correct 885 ms 47444 KB Output is correct
58 Correct 902 ms 47352 KB Output is correct
59 Correct 899 ms 47484 KB Output is correct
60 Correct 951 ms 47436 KB Output is correct
61 Correct 947 ms 47480 KB Output is correct
62 Correct 873 ms 47352 KB Output is correct
63 Correct 869 ms 47492 KB Output is correct
64 Correct 871 ms 47480 KB Output is correct
65 Correct 870 ms 47484 KB Output is correct
66 Correct 903 ms 47480 KB Output is correct
67 Correct 881 ms 47436 KB Output is correct
68 Correct 871 ms 47356 KB Output is correct
69 Correct 884 ms 47480 KB Output is correct
70 Correct 898 ms 47408 KB Output is correct
71 Correct 883 ms 47352 KB Output is correct
72 Correct 888 ms 47352 KB Output is correct
73 Correct 882 ms 47352 KB Output is correct
74 Correct 882 ms 47444 KB Output is correct
75 Correct 890 ms 47452 KB Output is correct
76 Correct 881 ms 47552 KB Output is correct
77 Correct 881 ms 47480 KB Output is correct
78 Correct 888 ms 47400 KB Output is correct
79 Correct 881 ms 47480 KB Output is correct
80 Correct 898 ms 47432 KB Output is correct
81 Correct 883 ms 47480 KB Output is correct
82 Correct 881 ms 47504 KB Output is correct
83 Correct 939 ms 47352 KB Output is correct
84 Correct 941 ms 47480 KB Output is correct
85 Correct 878 ms 47580 KB Output is correct
86 Correct 922 ms 47476 KB Output is correct
87 Correct 937 ms 47480 KB Output is correct
88 Correct 883 ms 47352 KB Output is correct
89 Correct 884 ms 47352 KB Output is correct
90 Correct 956 ms 47452 KB Output is correct
91 Correct 880 ms 47436 KB Output is correct
92 Correct 886 ms 47480 KB Output is correct
93 Correct 889 ms 47452 KB Output is correct
94 Correct 896 ms 47440 KB Output is correct
95 Correct 897 ms 47608 KB Output is correct
96 Correct 881 ms 47324 KB Output is correct
97 Correct 949 ms 47480 KB Output is correct
98 Correct 904 ms 47352 KB Output is correct
99 Correct 881 ms 47448 KB Output is correct
100 Correct 713 ms 47536 KB Output is correct
101 Correct 706 ms 47480 KB Output is correct
102 Correct 710 ms 47480 KB Output is correct
103 Correct 712 ms 47352 KB Output is correct
104 Correct 711 ms 47480 KB Output is correct
105 Correct 743 ms 47352 KB Output is correct
106 Correct 748 ms 47528 KB Output is correct
107 Correct 741 ms 47224 KB Output is correct
108 Correct 750 ms 47480 KB Output is correct
109 Correct 745 ms 47352 KB Output is correct
110 Correct 700 ms 47352 KB Output is correct
111 Correct 707 ms 47412 KB Output is correct
112 Correct 702 ms 47496 KB Output is correct
113 Correct 709 ms 47324 KB Output is correct
114 Correct 727 ms 47352 KB Output is correct
115 Correct 703 ms 47420 KB Output is correct
116 Correct 698 ms 47352 KB Output is correct
117 Correct 699 ms 47412 KB Output is correct
118 Correct 702 ms 47352 KB Output is correct
119 Correct 703 ms 47480 KB Output is correct
120 Correct 2 ms 296 KB Output is correct
121 Correct 2 ms 248 KB Output is correct
122 Correct 920 ms 47432 KB Output is correct
123 Correct 898 ms 47440 KB Output is correct
124 Correct 874 ms 47448 KB Output is correct
125 Correct 872 ms 47444 KB Output is correct
126 Correct 905 ms 47440 KB Output is correct
127 Correct 870 ms 47608 KB Output is correct
128 Correct 882 ms 47480 KB Output is correct
129 Correct 883 ms 47480 KB Output is correct
130 Correct 987 ms 47356 KB Output is correct
131 Correct 903 ms 47452 KB Output is correct
132 Correct 867 ms 47356 KB Output is correct
133 Correct 867 ms 47352 KB Output is correct