답안 #580269

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580269 2022-06-20T23:51:14 Z lkh3happy Bulldozer (JOI17_bulldozer) C++17
75 / 100
1136 ms 17248 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=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);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 432 KB Output is correct
2 Correct 2 ms 432 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 432 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Incorrect 2 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 432 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 444 KB Output is correct
11 Correct 0 ms 228 KB Output is correct
12 Correct 1 ms 228 KB Output is correct
13 Correct 0 ms 228 KB Output is correct
14 Correct 1 ms 228 KB Output is correct
15 Correct 1 ms 228 KB Output is correct
16 Correct 1 ms 228 KB Output is correct
17 Correct 0 ms 228 KB Output is correct
18 Correct 0 ms 228 KB Output is correct
19 Correct 1 ms 356 KB Output is correct
20 Correct 0 ms 228 KB Output is correct
21 Correct 2 ms 356 KB Output is correct
22 Correct 2 ms 356 KB Output is correct
23 Correct 2 ms 448 KB Output is correct
24 Correct 2 ms 356 KB Output is correct
25 Correct 2 ms 356 KB Output is correct
26 Correct 2 ms 356 KB Output is correct
27 Correct 2 ms 444 KB Output is correct
28 Correct 3 ms 356 KB Output is correct
29 Correct 2 ms 444 KB Output is correct
30 Correct 3 ms 356 KB Output is correct
31 Correct 2 ms 356 KB Output is correct
32 Correct 2 ms 348 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 432 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 444 KB Output is correct
11 Correct 0 ms 228 KB Output is correct
12 Correct 1 ms 228 KB Output is correct
13 Correct 0 ms 228 KB Output is correct
14 Correct 1 ms 228 KB Output is correct
15 Correct 1 ms 228 KB Output is correct
16 Correct 1 ms 228 KB Output is correct
17 Correct 0 ms 228 KB Output is correct
18 Correct 0 ms 228 KB Output is correct
19 Correct 1 ms 356 KB Output is correct
20 Correct 0 ms 228 KB Output is correct
21 Correct 2 ms 356 KB Output is correct
22 Correct 2 ms 356 KB Output is correct
23 Correct 2 ms 448 KB Output is correct
24 Correct 2 ms 356 KB Output is correct
25 Correct 2 ms 356 KB Output is correct
26 Correct 2 ms 356 KB Output is correct
27 Correct 2 ms 444 KB Output is correct
28 Correct 3 ms 356 KB Output is correct
29 Correct 2 ms 444 KB Output is correct
30 Correct 3 ms 356 KB Output is correct
31 Correct 2 ms 356 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 991 ms 17076 KB Output is correct
34 Correct 1004 ms 17084 KB Output is correct
35 Correct 1136 ms 17060 KB Output is correct
36 Correct 1006 ms 17116 KB Output is correct
37 Correct 1063 ms 17092 KB Output is correct
38 Correct 1014 ms 17096 KB Output is correct
39 Correct 934 ms 17128 KB Output is correct
40 Correct 934 ms 17076 KB Output is correct
41 Correct 935 ms 17076 KB Output is correct
42 Correct 929 ms 17084 KB Output is correct
43 Correct 936 ms 17084 KB Output is correct
44 Correct 925 ms 17156 KB Output is correct
45 Correct 930 ms 17116 KB Output is correct
46 Correct 927 ms 17100 KB Output is correct
47 Correct 923 ms 17084 KB Output is correct
48 Correct 960 ms 17076 KB Output is correct
49 Correct 923 ms 17056 KB Output is correct
50 Correct 925 ms 17100 KB Output is correct
51 Correct 909 ms 17076 KB Output is correct
52 Correct 914 ms 17140 KB Output is correct
53 Correct 916 ms 17060 KB Output is correct
54 Correct 936 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 432 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 444 KB Output is correct
11 Correct 0 ms 228 KB Output is correct
12 Correct 1 ms 228 KB Output is correct
13 Correct 0 ms 228 KB Output is correct
14 Correct 1 ms 228 KB Output is correct
15 Correct 1 ms 228 KB Output is correct
16 Correct 1 ms 228 KB Output is correct
17 Correct 0 ms 228 KB Output is correct
18 Correct 0 ms 228 KB Output is correct
19 Correct 1 ms 356 KB Output is correct
20 Correct 0 ms 228 KB Output is correct
21 Correct 2 ms 356 KB Output is correct
22 Correct 2 ms 356 KB Output is correct
23 Correct 2 ms 448 KB Output is correct
24 Correct 2 ms 356 KB Output is correct
25 Correct 2 ms 356 KB Output is correct
26 Correct 2 ms 356 KB Output is correct
27 Correct 2 ms 444 KB Output is correct
28 Correct 3 ms 356 KB Output is correct
29 Correct 2 ms 444 KB Output is correct
30 Correct 3 ms 356 KB Output is correct
31 Correct 2 ms 356 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 991 ms 17076 KB Output is correct
34 Correct 1004 ms 17084 KB Output is correct
35 Correct 1136 ms 17060 KB Output is correct
36 Correct 1006 ms 17116 KB Output is correct
37 Correct 1063 ms 17092 KB Output is correct
38 Correct 1014 ms 17096 KB Output is correct
39 Correct 934 ms 17128 KB Output is correct
40 Correct 934 ms 17076 KB Output is correct
41 Correct 935 ms 17076 KB Output is correct
42 Correct 929 ms 17084 KB Output is correct
43 Correct 936 ms 17084 KB Output is correct
44 Correct 925 ms 17156 KB Output is correct
45 Correct 930 ms 17116 KB Output is correct
46 Correct 927 ms 17100 KB Output is correct
47 Correct 923 ms 17084 KB Output is correct
48 Correct 960 ms 17076 KB Output is correct
49 Correct 923 ms 17056 KB Output is correct
50 Correct 925 ms 17100 KB Output is correct
51 Correct 909 ms 17076 KB Output is correct
52 Correct 914 ms 17140 KB Output is correct
53 Correct 916 ms 17060 KB Output is correct
54 Correct 936 ms 17084 KB Output is correct
55 Correct 932 ms 17076 KB Output is correct
56 Correct 933 ms 17084 KB Output is correct
57 Correct 936 ms 17084 KB Output is correct
58 Correct 918 ms 17108 KB Output is correct
59 Correct 947 ms 17080 KB Output is correct
60 Correct 930 ms 17100 KB Output is correct
61 Correct 932 ms 17084 KB Output is correct
62 Correct 972 ms 17080 KB Output is correct
63 Correct 932 ms 17076 KB Output is correct
64 Correct 949 ms 17060 KB Output is correct
65 Correct 918 ms 17072 KB Output is correct
66 Correct 938 ms 17076 KB Output is correct
67 Correct 923 ms 17116 KB Output is correct
68 Correct 932 ms 17044 KB Output is correct
69 Correct 914 ms 17112 KB Output is correct
70 Correct 921 ms 17248 KB Output is correct
71 Correct 920 ms 17084 KB Output is correct
72 Correct 927 ms 17072 KB Output is correct
73 Correct 899 ms 17160 KB Output is correct
74 Correct 913 ms 17084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 432 KB Output is correct
2 Correct 2 ms 432 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 432 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Incorrect 2 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -