Submission #580272

# Submission time Handle Problem Language Result Execution time Memory
580272 2022-06-20T23:58:35 Z lkh3happy Bulldozer (JOI17_bulldozer) C++17
75 / 100
1044 ms 17200 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)) 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:51: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]
   51 |     for(int a=0, b=0;a<v.size();a=b){
      |                      ~^~~~~~~~~
bulldozer.cpp:52: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]
   52 |         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);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 2 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 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 1 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 2 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 3 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 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 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 1 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 2 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 3 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 420 KB Output is correct
33 Correct 1039 ms 17024 KB Output is correct
34 Correct 972 ms 17084 KB Output is correct
35 Correct 1006 ms 17008 KB Output is correct
36 Correct 994 ms 17084 KB Output is correct
37 Correct 1002 ms 17016 KB Output is correct
38 Correct 974 ms 17112 KB Output is correct
39 Correct 977 ms 17084 KB Output is correct
40 Correct 996 ms 17016 KB Output is correct
41 Correct 971 ms 17084 KB Output is correct
42 Correct 969 ms 17084 KB Output is correct
43 Correct 993 ms 17012 KB Output is correct
44 Correct 967 ms 17084 KB Output is correct
45 Correct 956 ms 17084 KB Output is correct
46 Correct 995 ms 17084 KB Output is correct
47 Correct 943 ms 17200 KB Output is correct
48 Correct 972 ms 17076 KB Output is correct
49 Correct 981 ms 17076 KB Output is correct
50 Correct 988 ms 17032 KB Output is correct
51 Correct 976 ms 16976 KB Output is correct
52 Correct 991 ms 17036 KB Output is correct
53 Correct 974 ms 17072 KB Output is correct
54 Correct 961 ms 17024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 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 1 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 2 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 3 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 420 KB Output is correct
33 Correct 1039 ms 17024 KB Output is correct
34 Correct 972 ms 17084 KB Output is correct
35 Correct 1006 ms 17008 KB Output is correct
36 Correct 994 ms 17084 KB Output is correct
37 Correct 1002 ms 17016 KB Output is correct
38 Correct 974 ms 17112 KB Output is correct
39 Correct 977 ms 17084 KB Output is correct
40 Correct 996 ms 17016 KB Output is correct
41 Correct 971 ms 17084 KB Output is correct
42 Correct 969 ms 17084 KB Output is correct
43 Correct 993 ms 17012 KB Output is correct
44 Correct 967 ms 17084 KB Output is correct
45 Correct 956 ms 17084 KB Output is correct
46 Correct 995 ms 17084 KB Output is correct
47 Correct 943 ms 17200 KB Output is correct
48 Correct 972 ms 17076 KB Output is correct
49 Correct 981 ms 17076 KB Output is correct
50 Correct 988 ms 17032 KB Output is correct
51 Correct 976 ms 16976 KB Output is correct
52 Correct 991 ms 17036 KB Output is correct
53 Correct 974 ms 17072 KB Output is correct
54 Correct 961 ms 17024 KB Output is correct
55 Correct 963 ms 17056 KB Output is correct
56 Correct 960 ms 17020 KB Output is correct
57 Correct 1020 ms 17084 KB Output is correct
58 Correct 1044 ms 17052 KB Output is correct
59 Correct 978 ms 17084 KB Output is correct
60 Correct 1018 ms 17084 KB Output is correct
61 Correct 986 ms 17084 KB Output is correct
62 Correct 1000 ms 17084 KB Output is correct
63 Correct 972 ms 17084 KB Output is correct
64 Correct 949 ms 17012 KB Output is correct
65 Correct 996 ms 17084 KB Output is correct
66 Correct 967 ms 17072 KB Output is correct
67 Correct 972 ms 17072 KB Output is correct
68 Correct 1014 ms 17008 KB Output is correct
69 Correct 1020 ms 17076 KB Output is correct
70 Correct 982 ms 17084 KB Output is correct
71 Correct 985 ms 17084 KB Output is correct
72 Correct 986 ms 17084 KB Output is correct
73 Correct 993 ms 17020 KB Output is correct
74 Correct 944 ms 17056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 2 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -