# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
590573 |
2022-07-06T06:44:25 Z |
반딧불(#8412) |
Bulldozer (JOI17_bulldozer) |
C++17 |
|
1034 ms |
82836 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(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)\n", X, Y, tmp.slope.x, tmp.slope.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 |
1168 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 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 |
2 ms |
692 KB |
Output is correct |
6 |
Correct |
2 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 |
692 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
692 KB |
Output is correct |
22 |
Correct |
2 ms |
692 KB |
Output is correct |
23 |
Correct |
2 ms |
792 KB |
Output is correct |
24 |
Correct |
2 ms |
692 KB |
Output is correct |
25 |
Correct |
2 ms |
712 KB |
Output is correct |
26 |
Correct |
2 ms |
692 KB |
Output is correct |
27 |
Correct |
2 ms |
692 KB |
Output is correct |
28 |
Correct |
3 ms |
692 KB |
Output is correct |
29 |
Correct |
2 ms |
692 KB |
Output is correct |
30 |
Correct |
2 ms |
692 KB |
Output is correct |
31 |
Correct |
3 ms |
820 KB |
Output is correct |
32 |
Correct |
2 ms |
788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 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 |
2 ms |
692 KB |
Output is correct |
6 |
Correct |
2 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 |
692 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
692 KB |
Output is correct |
22 |
Correct |
2 ms |
692 KB |
Output is correct |
23 |
Correct |
2 ms |
792 KB |
Output is correct |
24 |
Correct |
2 ms |
692 KB |
Output is correct |
25 |
Correct |
2 ms |
712 KB |
Output is correct |
26 |
Correct |
2 ms |
692 KB |
Output is correct |
27 |
Correct |
2 ms |
692 KB |
Output is correct |
28 |
Correct |
3 ms |
692 KB |
Output is correct |
29 |
Correct |
2 ms |
692 KB |
Output is correct |
30 |
Correct |
2 ms |
692 KB |
Output is correct |
31 |
Correct |
3 ms |
820 KB |
Output is correct |
32 |
Correct |
2 ms |
788 KB |
Output is correct |
33 |
Correct |
1012 ms |
82768 KB |
Output is correct |
34 |
Correct |
980 ms |
82668 KB |
Output is correct |
35 |
Correct |
991 ms |
82708 KB |
Output is correct |
36 |
Correct |
963 ms |
82680 KB |
Output is correct |
37 |
Correct |
981 ms |
82736 KB |
Output is correct |
38 |
Correct |
947 ms |
82828 KB |
Output is correct |
39 |
Correct |
961 ms |
82692 KB |
Output is correct |
40 |
Correct |
969 ms |
82792 KB |
Output is correct |
41 |
Correct |
977 ms |
82728 KB |
Output is correct |
42 |
Correct |
953 ms |
82776 KB |
Output is correct |
43 |
Correct |
992 ms |
82648 KB |
Output is correct |
44 |
Correct |
914 ms |
82672 KB |
Output is correct |
45 |
Correct |
951 ms |
82740 KB |
Output is correct |
46 |
Correct |
949 ms |
82736 KB |
Output is correct |
47 |
Correct |
936 ms |
82648 KB |
Output is correct |
48 |
Correct |
936 ms |
82652 KB |
Output is correct |
49 |
Correct |
946 ms |
82664 KB |
Output is correct |
50 |
Correct |
932 ms |
82652 KB |
Output is correct |
51 |
Correct |
958 ms |
82612 KB |
Output is correct |
52 |
Correct |
949 ms |
82684 KB |
Output is correct |
53 |
Correct |
906 ms |
82836 KB |
Output is correct |
54 |
Correct |
929 ms |
82620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 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 |
2 ms |
692 KB |
Output is correct |
6 |
Correct |
2 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 |
692 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
692 KB |
Output is correct |
22 |
Correct |
2 ms |
692 KB |
Output is correct |
23 |
Correct |
2 ms |
792 KB |
Output is correct |
24 |
Correct |
2 ms |
692 KB |
Output is correct |
25 |
Correct |
2 ms |
712 KB |
Output is correct |
26 |
Correct |
2 ms |
692 KB |
Output is correct |
27 |
Correct |
2 ms |
692 KB |
Output is correct |
28 |
Correct |
3 ms |
692 KB |
Output is correct |
29 |
Correct |
2 ms |
692 KB |
Output is correct |
30 |
Correct |
2 ms |
692 KB |
Output is correct |
31 |
Correct |
3 ms |
820 KB |
Output is correct |
32 |
Correct |
2 ms |
788 KB |
Output is correct |
33 |
Correct |
1012 ms |
82768 KB |
Output is correct |
34 |
Correct |
980 ms |
82668 KB |
Output is correct |
35 |
Correct |
991 ms |
82708 KB |
Output is correct |
36 |
Correct |
963 ms |
82680 KB |
Output is correct |
37 |
Correct |
981 ms |
82736 KB |
Output is correct |
38 |
Correct |
947 ms |
82828 KB |
Output is correct |
39 |
Correct |
961 ms |
82692 KB |
Output is correct |
40 |
Correct |
969 ms |
82792 KB |
Output is correct |
41 |
Correct |
977 ms |
82728 KB |
Output is correct |
42 |
Correct |
953 ms |
82776 KB |
Output is correct |
43 |
Correct |
992 ms |
82648 KB |
Output is correct |
44 |
Correct |
914 ms |
82672 KB |
Output is correct |
45 |
Correct |
951 ms |
82740 KB |
Output is correct |
46 |
Correct |
949 ms |
82736 KB |
Output is correct |
47 |
Correct |
936 ms |
82648 KB |
Output is correct |
48 |
Correct |
936 ms |
82652 KB |
Output is correct |
49 |
Correct |
946 ms |
82664 KB |
Output is correct |
50 |
Correct |
932 ms |
82652 KB |
Output is correct |
51 |
Correct |
958 ms |
82612 KB |
Output is correct |
52 |
Correct |
949 ms |
82684 KB |
Output is correct |
53 |
Correct |
906 ms |
82836 KB |
Output is correct |
54 |
Correct |
929 ms |
82620 KB |
Output is correct |
55 |
Correct |
956 ms |
82632 KB |
Output is correct |
56 |
Correct |
954 ms |
82588 KB |
Output is correct |
57 |
Correct |
1000 ms |
82632 KB |
Output is correct |
58 |
Correct |
979 ms |
82668 KB |
Output is correct |
59 |
Correct |
991 ms |
82700 KB |
Output is correct |
60 |
Correct |
1004 ms |
82716 KB |
Output is correct |
61 |
Correct |
969 ms |
82652 KB |
Output is correct |
62 |
Correct |
992 ms |
82584 KB |
Output is correct |
63 |
Correct |
1010 ms |
82652 KB |
Output is correct |
64 |
Correct |
990 ms |
82748 KB |
Output is correct |
65 |
Correct |
1034 ms |
82600 KB |
Output is correct |
66 |
Correct |
1006 ms |
82680 KB |
Output is correct |
67 |
Correct |
1000 ms |
82788 KB |
Output is correct |
68 |
Correct |
973 ms |
82788 KB |
Output is correct |
69 |
Correct |
997 ms |
82756 KB |
Output is correct |
70 |
Correct |
966 ms |
82760 KB |
Output is correct |
71 |
Correct |
992 ms |
82712 KB |
Output is correct |
72 |
Correct |
998 ms |
82760 KB |
Output is correct |
73 |
Correct |
978 ms |
82652 KB |
Output is correct |
74 |
Correct |
979 ms |
82716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
1168 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |