답안 #580273

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580273 2022-06-21T00:02:35 Z lkh3happy Bulldozer (JOI17_bulldozer) C++14
100 / 100
1090 ms 17112 KB
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

struct st{
    long long lmx=-1e18, rmx=-1e18, mx=-1e18, sum=0;
}t[8001];

struct st1{
    long long first, second, c;
}A[2001], now[2001];

st operator + (st a, st b){
    return {max(a.lmx, a.sum+b.lmx), max(a.rmx+b.sum, b.rmx), max(max(a.mx, b.mx), a.rmx+b.lmx), a.sum+b.sum};
}

bool operator < (st1 a, st1 b){
    if(a.first==b.first) return a.second<b.second;
    return a.first<b.first;
}

vector<pair<int, int> > v;
int pos[2001];

void upd(int l, int r, int n, int x, int y){
    if(x<l || r<x) return;
    if(l==r){
        t[n].lmx=t[n].rmx=t[n].mx=max(0, y);
        t[n].sum=y;
        return;
    }
    int m=l+r>>1;
    upd(l, m, n*2, x, y); upd(m+1, r, n*2+1, x, y);
    t[n]=t[n*2]+t[n*2+1];
    return;
}

int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++) scanf("%lld %lld %lld\n", &A[i].first, &A[i].second, &A[i].c);
    sort(A+1, A+n+1);
    for(int i=1;i<=n;i++) pos[i]=i, now[i]=A[i], upd(1, n, 1, i, A[i].c);
    for(int i=1;i<n;i++) for(int j=i+1;j<=n;j++) if(A[i].first^A[j].first) v.push_back({i, j});
    sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b){
        if((A[a.second].second-A[a.first].second)*(A[b.second].first-A[b.first].first)==(A[b.second].second-A[b.first].second)*(A[a.second].first-A[a.first].first)){
            if(a.first==b.first) return A[a.second]<A[b.second];
            return A[a.first]<A[b.first];
        }
        return ((A[a.second].second-A[a.first].second)*(A[b.second].first-A[b.first].first)<(A[b.second].second-A[b.first].second)*(A[a.second].first-A[a.first].first));
    });
    long long mx=max(0LL, t[1].mx);
    for(int a=0, b=0;a<v.size();a=b){
        while(b<v.size() && (A[v[a].second].second-A[v[a].first].second)*(A[v[b].second].first-A[v[b].first].first)==(A[v[b].second].second-A[v[b].first].second)*(A[v[a].second].first-A[v[a].first].first)) b++;
        for(int k=a;k<b;k++){
            int i=v[k].first, j=v[k].second;
            swap(now[pos[i]], now[pos[j]]);
            swap(pos[i], pos[j]);
            upd(1, n, 1, pos[i], now[pos[i]].c);
            upd(1, n, 1, pos[j], now[pos[j]].c);
        }
        mx=max(mx, t[1].mx);
    }
    printf("%lld\n", mx);
    return 0;
}

Compilation message

bulldozer.cpp: In function 'void upd(int, int, int, int, int)':
bulldozer.cpp:33:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |     int m=l+r>>1;
      |           ~^~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for(int a=0, b=0;a<v.size();a=b){
      |                      ~^~~~~~~~~
bulldozer.cpp:55:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         while(b<v.size() && (A[v[a].second].second-A[v[a].first].second)*(A[v[b].second].first-A[v[b].first].first)==(A[v[b].second].second-A[v[b].first].second)*(A[v[a].second].first-A[v[a].first].first)) b++;
      |               ~^~~~~~~~~
bulldozer.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
bulldozer.cpp:42:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     for(int i=1;i<=n;i++) scanf("%lld %lld %lld\n", &A[i].first, &A[i].second, &A[i].c);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 428 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 0 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 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 0 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 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1004 ms 17056 KB Output is correct
34 Correct 977 ms 17080 KB Output is correct
35 Correct 999 ms 17056 KB Output is correct
36 Correct 977 ms 17084 KB Output is correct
37 Correct 972 ms 17032 KB Output is correct
38 Correct 960 ms 17084 KB Output is correct
39 Correct 984 ms 17076 KB Output is correct
40 Correct 1000 ms 17012 KB Output is correct
41 Correct 983 ms 17084 KB Output is correct
42 Correct 990 ms 17084 KB Output is correct
43 Correct 986 ms 17084 KB Output is correct
44 Correct 956 ms 17084 KB Output is correct
45 Correct 973 ms 17076 KB Output is correct
46 Correct 967 ms 17012 KB Output is correct
47 Correct 979 ms 17060 KB Output is correct
48 Correct 958 ms 17076 KB Output is correct
49 Correct 975 ms 17084 KB Output is correct
50 Correct 977 ms 17020 KB Output is correct
51 Correct 977 ms 17000 KB Output is correct
52 Correct 986 ms 17028 KB Output is correct
53 Correct 965 ms 17064 KB Output is correct
54 Correct 992 ms 17084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 0 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 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1004 ms 17056 KB Output is correct
34 Correct 977 ms 17080 KB Output is correct
35 Correct 999 ms 17056 KB Output is correct
36 Correct 977 ms 17084 KB Output is correct
37 Correct 972 ms 17032 KB Output is correct
38 Correct 960 ms 17084 KB Output is correct
39 Correct 984 ms 17076 KB Output is correct
40 Correct 1000 ms 17012 KB Output is correct
41 Correct 983 ms 17084 KB Output is correct
42 Correct 990 ms 17084 KB Output is correct
43 Correct 986 ms 17084 KB Output is correct
44 Correct 956 ms 17084 KB Output is correct
45 Correct 973 ms 17076 KB Output is correct
46 Correct 967 ms 17012 KB Output is correct
47 Correct 979 ms 17060 KB Output is correct
48 Correct 958 ms 17076 KB Output is correct
49 Correct 975 ms 17084 KB Output is correct
50 Correct 977 ms 17020 KB Output is correct
51 Correct 977 ms 17000 KB Output is correct
52 Correct 986 ms 17028 KB Output is correct
53 Correct 965 ms 17064 KB Output is correct
54 Correct 992 ms 17084 KB Output is correct
55 Correct 1000 ms 17084 KB Output is correct
56 Correct 987 ms 17084 KB Output is correct
57 Correct 989 ms 17000 KB Output is correct
58 Correct 968 ms 17084 KB Output is correct
59 Correct 986 ms 17084 KB Output is correct
60 Correct 985 ms 17084 KB Output is correct
61 Correct 990 ms 17084 KB Output is correct
62 Correct 996 ms 17084 KB Output is correct
63 Correct 991 ms 17076 KB Output is correct
64 Correct 985 ms 17084 KB Output is correct
65 Correct 980 ms 17076 KB Output is correct
66 Correct 999 ms 17084 KB Output is correct
67 Correct 1008 ms 17084 KB Output is correct
68 Correct 1047 ms 17020 KB Output is correct
69 Correct 1087 ms 17052 KB Output is correct
70 Correct 1082 ms 17052 KB Output is correct
71 Correct 1090 ms 17016 KB Output is correct
72 Correct 1037 ms 17084 KB Output is correct
73 Correct 1024 ms 17084 KB Output is correct
74 Correct 1014 ms 17036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 428 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 0 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 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 0 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 2 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 2 ms 340 KB Output is correct
39 Correct 3 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 1004 ms 17056 KB Output is correct
49 Correct 977 ms 17080 KB Output is correct
50 Correct 999 ms 17056 KB Output is correct
51 Correct 977 ms 17084 KB Output is correct
52 Correct 972 ms 17032 KB Output is correct
53 Correct 960 ms 17084 KB Output is correct
54 Correct 984 ms 17076 KB Output is correct
55 Correct 1000 ms 17012 KB Output is correct
56 Correct 983 ms 17084 KB Output is correct
57 Correct 990 ms 17084 KB Output is correct
58 Correct 986 ms 17084 KB Output is correct
59 Correct 956 ms 17084 KB Output is correct
60 Correct 973 ms 17076 KB Output is correct
61 Correct 967 ms 17012 KB Output is correct
62 Correct 979 ms 17060 KB Output is correct
63 Correct 958 ms 17076 KB Output is correct
64 Correct 975 ms 17084 KB Output is correct
65 Correct 977 ms 17020 KB Output is correct
66 Correct 977 ms 17000 KB Output is correct
67 Correct 986 ms 17028 KB Output is correct
68 Correct 965 ms 17064 KB Output is correct
69 Correct 992 ms 17084 KB Output is correct
70 Correct 1000 ms 17084 KB Output is correct
71 Correct 987 ms 17084 KB Output is correct
72 Correct 989 ms 17000 KB Output is correct
73 Correct 968 ms 17084 KB Output is correct
74 Correct 986 ms 17084 KB Output is correct
75 Correct 985 ms 17084 KB Output is correct
76 Correct 990 ms 17084 KB Output is correct
77 Correct 996 ms 17084 KB Output is correct
78 Correct 991 ms 17076 KB Output is correct
79 Correct 985 ms 17084 KB Output is correct
80 Correct 980 ms 17076 KB Output is correct
81 Correct 999 ms 17084 KB Output is correct
82 Correct 1008 ms 17084 KB Output is correct
83 Correct 1047 ms 17020 KB Output is correct
84 Correct 1087 ms 17052 KB Output is correct
85 Correct 1082 ms 17052 KB Output is correct
86 Correct 1090 ms 17016 KB Output is correct
87 Correct 1037 ms 17084 KB Output is correct
88 Correct 1024 ms 17084 KB Output is correct
89 Correct 1014 ms 17036 KB Output is correct
90 Correct 1050 ms 17100 KB Output is correct
91 Correct 1051 ms 17092 KB Output is correct
92 Correct 1060 ms 17112 KB Output is correct
93 Correct 1046 ms 17096 KB Output is correct
94 Correct 990 ms 17076 KB Output is correct
95 Correct 983 ms 17068 KB Output is correct
96 Correct 983 ms 17072 KB Output is correct
97 Correct 1000 ms 17040 KB Output is correct
98 Correct 963 ms 17072 KB Output is correct
99 Correct 977 ms 17060 KB Output is correct
100 Correct 450 ms 8896 KB Output is correct
101 Correct 437 ms 8872 KB Output is correct
102 Correct 496 ms 8896 KB Output is correct
103 Correct 440 ms 8888 KB Output is correct
104 Correct 446 ms 8896 KB Output is correct
105 Correct 612 ms 17100 KB Output is correct
106 Correct 617 ms 17084 KB Output is correct
107 Correct 613 ms 17076 KB Output is correct
108 Correct 610 ms 17076 KB Output is correct
109 Correct 607 ms 17060 KB Output is correct
110 Correct 942 ms 17108 KB Output is correct
111 Correct 937 ms 17084 KB Output is correct
112 Correct 943 ms 17088 KB Output is correct
113 Correct 943 ms 17084 KB Output is correct
114 Correct 950 ms 17084 KB Output is correct
115 Correct 949 ms 17084 KB Output is correct
116 Correct 931 ms 17084 KB Output is correct
117 Correct 937 ms 17072 KB Output is correct
118 Correct 935 ms 17084 KB Output is correct
119 Correct 941 ms 17076 KB Output is correct
120 Correct 0 ms 300 KB Output is correct
121 Correct 0 ms 212 KB Output is correct
122 Correct 995 ms 17076 KB Output is correct
123 Correct 985 ms 17084 KB Output is correct
124 Correct 970 ms 17084 KB Output is correct
125 Correct 979 ms 17076 KB Output is correct
126 Correct 979 ms 17084 KB Output is correct
127 Correct 970 ms 17076 KB Output is correct
128 Correct 967 ms 17108 KB Output is correct
129 Correct 995 ms 17092 KB Output is correct
130 Correct 984 ms 17084 KB Output is correct
131 Correct 983 ms 17076 KB Output is correct
132 Correct 972 ms 17100 KB Output is correct
133 Correct 978 ms 17084 KB Output is correct