답안 #1078844

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078844 2024-08-28T07:02:38 Z vnm06 Bulldozer (JOI17_bulldozer) C++14
100 / 100
1407 ms 251316 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

struct Point
{
    long long x, y, val, nom;
    Point() {}
    Point(long long a, long long b, long long c, long long d)
    {
        x=a;
        y=b;
        val=c;
        nom=d;
    }
};

bool operator<(Point p, Point q)
{
    if(p.x==q.x) return p.y>q.y;
    return p.x<q.x;
}

struct Line
{
    Point a, b;
    Line() {}
    Line(Point p, Point q)
    {
        a.x=p.x;
        a.y=p.y;
        a.val=p.val;
        a.nom=p.nom;
        b.x=q.x;
        b.y=q.y;
        b.val=q.val;
        b.nom=q.nom;
    }
};

bool cmp(Line p, Line q)
{
    if(p.a.x==p.b.x && q.a.x==q.b.x) return (p.a.y-p.b.y) > (q.a.y-q.b.y);
    if(p.a.x==p.b.x) return 1;
    if(q.a.x==q.b.x) return 0;
    if(((p.b.y-p.a.y) * (q.b.x-q.a.x)) == ((q.b.y-q.a.y) * (p.b.x-p.a.x))) return (p.b.x-p.a.x) > (q.b.x-q.a.x);
    return ((p.b.y-p.a.y) * (q.b.x-q.a.x)) < ((q.b.y-q.a.y) * (p.b.x-p.a.x));
}

bool operator==(Line p, Line q)
{
    return ((p.b.y-p.a.y) * (q.b.x-q.a.x)) == ((q.b.y-q.a.y) * (p.b.x-p.a.x));
}

int n, brl=0;
int pos[2005];
Point P[2005];

vector<Line> L;

long long ans=0;
long long A[2005];

void solve()
{
    long long res=0;
    for(long long i=0; i<n; i++)
    {
        res+=A[i];
        if(res<0) res=0;
        if(res>ans) ans=res;
    }
}

long long sum[8005], pref[8005], suf[8005], mx[8005];

void update(int v, int le, int ri, int id, long long val)
{
    if(le==ri)
    {
        sum[v]=val;
        pref[v]=max(sum[v], 0LL);
        suf[v]=max(sum[v], 0LL);
        mx[v]=max(sum[v], 0LL);
        return;
    }
    int mid=(le+ri)/2;
    if(id<=mid) update(2*v, le, mid, id, val);
    else update(2*v+1, mid+1, ri, id, val);

    sum[v]=sum[2*v]+sum[2*v+1];
    pref[v]=max(pref[2*v], sum[2*v]+pref[2*v+1]);
    suf[v]=max(suf[2*v+1], suf[2*v]+sum[2*v+1]);
    mx[v]=max(max(mx[2*v], mx[2*v+1]), suf[2*v]+pref[2*v+1]);
}

bool nepip[2005];
vector<int> upd;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(long long i=0; i<n; i++) cin>>P[i].x>>P[i].y>>P[i].val;
    sort(P, P+n);
    for(long long i=0; i<n; i++) P[i].nom=i;
    for(long long i=0; i<n; i++)
    {
        A[i]=P[i].val;
        pos[i]=i;
        for(long long j=i+1; j<n; j++)
        {
            L.push_back(Line(P[i], P[j]));
            ///cout<<L[brl].a.x<<" "<<L[brl].a.y<<" "<<L[brl].b.x<<" "<<L[brl].b.y<<"\n";
            brl++;
        }
    }
    ///cout<<brl<<endl;
    stable_sort(L.begin(), L.end(), cmp);

    for(int i=0; i<n; i++)
    {
        update(1, 0, n-1, i, A[i]);
    }

    for(int i=0; i<brl; i++)
    {
        if(i==0 || !(L[i]==L[i-1])) 
        {
            ans=max(ans, mx[1]);
            for(int j=0; j<upd.size(); j++) nepip[upd[j]]=0;
            upd.resize(0);
        }
        Point t1=L[i].a, t2=L[i].b;
        if(nepip[pos[t1.nom]] || nepip[pos[t2.nom]]) continue;
        update(1, 0, n-1, pos[t2.nom], A[pos[t1.nom]]);
        update(1, 0, n-1, pos[t1.nom], A[pos[t2.nom]]);
        swap(A[pos[t1.nom]], A[pos[t2.nom]]);
        swap(pos[t1.nom], pos[t2.nom]);
        nepip[pos[t1.nom]]=1;
        nepip[pos[t2.nom]]=1;
        upd.push_back(pos[t1.nom]);
        upd.push_back(pos[t2.nom]);
    }
    ans=max(ans, mx[1]);
    cout<<ans<<endl;
    return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:135:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |             for(int j=0; j<upd.size(); j++) nepip[upd[j]]=0;
      |                          ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1244 KB Output is correct
2 Correct 1 ms 1244 KB Output is correct
3 Correct 2 ms 1244 KB Output is correct
4 Correct 1 ms 1244 KB Output is correct
5 Correct 1 ms 1244 KB Output is correct
6 Correct 1 ms 1244 KB Output is correct
7 Correct 1 ms 1140 KB Output is correct
8 Correct 2 ms 1244 KB Output is correct
9 Correct 1 ms 1244 KB Output is correct
10 Correct 1 ms 1244 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1244 KB Output is correct
2 Correct 2 ms 1244 KB Output is correct
3 Correct 2 ms 1244 KB Output is correct
4 Correct 2 ms 1244 KB Output is correct
5 Correct 2 ms 1244 KB Output is correct
6 Correct 2 ms 1240 KB Output is correct
7 Correct 3 ms 1244 KB Output is correct
8 Correct 2 ms 1244 KB Output is correct
9 Correct 2 ms 1244 KB Output is correct
10 Correct 3 ms 1244 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 1244 KB Output is correct
22 Correct 3 ms 1244 KB Output is correct
23 Correct 3 ms 1244 KB Output is correct
24 Correct 2 ms 1244 KB Output is correct
25 Correct 3 ms 1244 KB Output is correct
26 Correct 2 ms 1116 KB Output is correct
27 Correct 2 ms 1244 KB Output is correct
28 Correct 2 ms 1244 KB Output is correct
29 Correct 2 ms 1244 KB Output is correct
30 Correct 2 ms 1244 KB Output is correct
31 Correct 2 ms 1244 KB Output is correct
32 Correct 2 ms 1244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1244 KB Output is correct
2 Correct 2 ms 1244 KB Output is correct
3 Correct 2 ms 1244 KB Output is correct
4 Correct 2 ms 1244 KB Output is correct
5 Correct 2 ms 1244 KB Output is correct
6 Correct 2 ms 1240 KB Output is correct
7 Correct 3 ms 1244 KB Output is correct
8 Correct 2 ms 1244 KB Output is correct
9 Correct 2 ms 1244 KB Output is correct
10 Correct 3 ms 1244 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 1244 KB Output is correct
22 Correct 3 ms 1244 KB Output is correct
23 Correct 3 ms 1244 KB Output is correct
24 Correct 2 ms 1244 KB Output is correct
25 Correct 3 ms 1244 KB Output is correct
26 Correct 2 ms 1116 KB Output is correct
27 Correct 2 ms 1244 KB Output is correct
28 Correct 2 ms 1244 KB Output is correct
29 Correct 2 ms 1244 KB Output is correct
30 Correct 2 ms 1244 KB Output is correct
31 Correct 2 ms 1244 KB Output is correct
32 Correct 2 ms 1244 KB Output is correct
33 Correct 1174 ms 250968 KB Output is correct
34 Correct 1167 ms 251056 KB Output is correct
35 Correct 1192 ms 251056 KB Output is correct
36 Correct 1160 ms 250976 KB Output is correct
37 Correct 1178 ms 251064 KB Output is correct
38 Correct 1197 ms 251060 KB Output is correct
39 Correct 1209 ms 250980 KB Output is correct
40 Correct 1173 ms 251048 KB Output is correct
41 Correct 1201 ms 251060 KB Output is correct
42 Correct 1167 ms 250996 KB Output is correct
43 Correct 1299 ms 251104 KB Output is correct
44 Correct 1255 ms 251060 KB Output is correct
45 Correct 1192 ms 250964 KB Output is correct
46 Correct 1183 ms 251052 KB Output is correct
47 Correct 1165 ms 251060 KB Output is correct
48 Correct 1169 ms 251028 KB Output is correct
49 Correct 1192 ms 251316 KB Output is correct
50 Correct 1231 ms 251060 KB Output is correct
51 Correct 1234 ms 251056 KB Output is correct
52 Correct 1209 ms 250988 KB Output is correct
53 Correct 1267 ms 251008 KB Output is correct
54 Correct 1206 ms 251048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1244 KB Output is correct
2 Correct 2 ms 1244 KB Output is correct
3 Correct 2 ms 1244 KB Output is correct
4 Correct 2 ms 1244 KB Output is correct
5 Correct 2 ms 1244 KB Output is correct
6 Correct 2 ms 1240 KB Output is correct
7 Correct 3 ms 1244 KB Output is correct
8 Correct 2 ms 1244 KB Output is correct
9 Correct 2 ms 1244 KB Output is correct
10 Correct 3 ms 1244 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 1244 KB Output is correct
22 Correct 3 ms 1244 KB Output is correct
23 Correct 3 ms 1244 KB Output is correct
24 Correct 2 ms 1244 KB Output is correct
25 Correct 3 ms 1244 KB Output is correct
26 Correct 2 ms 1116 KB Output is correct
27 Correct 2 ms 1244 KB Output is correct
28 Correct 2 ms 1244 KB Output is correct
29 Correct 2 ms 1244 KB Output is correct
30 Correct 2 ms 1244 KB Output is correct
31 Correct 2 ms 1244 KB Output is correct
32 Correct 2 ms 1244 KB Output is correct
33 Correct 1174 ms 250968 KB Output is correct
34 Correct 1167 ms 251056 KB Output is correct
35 Correct 1192 ms 251056 KB Output is correct
36 Correct 1160 ms 250976 KB Output is correct
37 Correct 1178 ms 251064 KB Output is correct
38 Correct 1197 ms 251060 KB Output is correct
39 Correct 1209 ms 250980 KB Output is correct
40 Correct 1173 ms 251048 KB Output is correct
41 Correct 1201 ms 251060 KB Output is correct
42 Correct 1167 ms 250996 KB Output is correct
43 Correct 1299 ms 251104 KB Output is correct
44 Correct 1255 ms 251060 KB Output is correct
45 Correct 1192 ms 250964 KB Output is correct
46 Correct 1183 ms 251052 KB Output is correct
47 Correct 1165 ms 251060 KB Output is correct
48 Correct 1169 ms 251028 KB Output is correct
49 Correct 1192 ms 251316 KB Output is correct
50 Correct 1231 ms 251060 KB Output is correct
51 Correct 1234 ms 251056 KB Output is correct
52 Correct 1209 ms 250988 KB Output is correct
53 Correct 1267 ms 251008 KB Output is correct
54 Correct 1206 ms 251048 KB Output is correct
55 Correct 1275 ms 250872 KB Output is correct
56 Correct 1193 ms 250880 KB Output is correct
57 Correct 1225 ms 251044 KB Output is correct
58 Correct 1263 ms 251108 KB Output is correct
59 Correct 1187 ms 251052 KB Output is correct
60 Correct 1195 ms 250932 KB Output is correct
61 Correct 1208 ms 250928 KB Output is correct
62 Correct 1165 ms 251056 KB Output is correct
63 Correct 1155 ms 250968 KB Output is correct
64 Correct 1210 ms 251056 KB Output is correct
65 Correct 1222 ms 251060 KB Output is correct
66 Correct 1199 ms 250948 KB Output is correct
67 Correct 1407 ms 251064 KB Output is correct
68 Correct 1171 ms 251052 KB Output is correct
69 Correct 1179 ms 251060 KB Output is correct
70 Correct 1203 ms 251016 KB Output is correct
71 Correct 1179 ms 251056 KB Output is correct
72 Correct 1173 ms 250888 KB Output is correct
73 Correct 1203 ms 251056 KB Output is correct
74 Correct 1165 ms 251056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1244 KB Output is correct
2 Correct 1 ms 1244 KB Output is correct
3 Correct 2 ms 1244 KB Output is correct
4 Correct 1 ms 1244 KB Output is correct
5 Correct 1 ms 1244 KB Output is correct
6 Correct 1 ms 1244 KB Output is correct
7 Correct 1 ms 1140 KB Output is correct
8 Correct 2 ms 1244 KB Output is correct
9 Correct 1 ms 1244 KB Output is correct
10 Correct 1 ms 1244 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 1244 KB Output is correct
17 Correct 2 ms 1244 KB Output is correct
18 Correct 2 ms 1244 KB Output is correct
19 Correct 2 ms 1244 KB Output is correct
20 Correct 2 ms 1244 KB Output is correct
21 Correct 2 ms 1240 KB Output is correct
22 Correct 3 ms 1244 KB Output is correct
23 Correct 2 ms 1244 KB Output is correct
24 Correct 2 ms 1244 KB Output is correct
25 Correct 3 ms 1244 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 2 ms 1244 KB Output is correct
37 Correct 3 ms 1244 KB Output is correct
38 Correct 3 ms 1244 KB Output is correct
39 Correct 2 ms 1244 KB Output is correct
40 Correct 3 ms 1244 KB Output is correct
41 Correct 2 ms 1116 KB Output is correct
42 Correct 2 ms 1244 KB Output is correct
43 Correct 2 ms 1244 KB Output is correct
44 Correct 2 ms 1244 KB Output is correct
45 Correct 2 ms 1244 KB Output is correct
46 Correct 2 ms 1244 KB Output is correct
47 Correct 2 ms 1244 KB Output is correct
48 Correct 1174 ms 250968 KB Output is correct
49 Correct 1167 ms 251056 KB Output is correct
50 Correct 1192 ms 251056 KB Output is correct
51 Correct 1160 ms 250976 KB Output is correct
52 Correct 1178 ms 251064 KB Output is correct
53 Correct 1197 ms 251060 KB Output is correct
54 Correct 1209 ms 250980 KB Output is correct
55 Correct 1173 ms 251048 KB Output is correct
56 Correct 1201 ms 251060 KB Output is correct
57 Correct 1167 ms 250996 KB Output is correct
58 Correct 1299 ms 251104 KB Output is correct
59 Correct 1255 ms 251060 KB Output is correct
60 Correct 1192 ms 250964 KB Output is correct
61 Correct 1183 ms 251052 KB Output is correct
62 Correct 1165 ms 251060 KB Output is correct
63 Correct 1169 ms 251028 KB Output is correct
64 Correct 1192 ms 251316 KB Output is correct
65 Correct 1231 ms 251060 KB Output is correct
66 Correct 1234 ms 251056 KB Output is correct
67 Correct 1209 ms 250988 KB Output is correct
68 Correct 1267 ms 251008 KB Output is correct
69 Correct 1206 ms 251048 KB Output is correct
70 Correct 1275 ms 250872 KB Output is correct
71 Correct 1193 ms 250880 KB Output is correct
72 Correct 1225 ms 251044 KB Output is correct
73 Correct 1263 ms 251108 KB Output is correct
74 Correct 1187 ms 251052 KB Output is correct
75 Correct 1195 ms 250932 KB Output is correct
76 Correct 1208 ms 250928 KB Output is correct
77 Correct 1165 ms 251056 KB Output is correct
78 Correct 1155 ms 250968 KB Output is correct
79 Correct 1210 ms 251056 KB Output is correct
80 Correct 1222 ms 251060 KB Output is correct
81 Correct 1199 ms 250948 KB Output is correct
82 Correct 1407 ms 251064 KB Output is correct
83 Correct 1171 ms 251052 KB Output is correct
84 Correct 1179 ms 251060 KB Output is correct
85 Correct 1203 ms 251016 KB Output is correct
86 Correct 1179 ms 251056 KB Output is correct
87 Correct 1173 ms 250888 KB Output is correct
88 Correct 1203 ms 251056 KB Output is correct
89 Correct 1165 ms 251056 KB Output is correct
90 Correct 1163 ms 251060 KB Output is correct
91 Correct 1182 ms 251056 KB Output is correct
92 Correct 1162 ms 251084 KB Output is correct
93 Correct 1176 ms 251040 KB Output is correct
94 Correct 1158 ms 251056 KB Output is correct
95 Correct 1230 ms 250976 KB Output is correct
96 Correct 1214 ms 251000 KB Output is correct
97 Correct 1177 ms 251056 KB Output is correct
98 Correct 1165 ms 251060 KB Output is correct
99 Correct 1175 ms 250900 KB Output is correct
100 Correct 813 ms 251060 KB Output is correct
101 Correct 813 ms 251060 KB Output is correct
102 Correct 823 ms 250948 KB Output is correct
103 Correct 854 ms 251060 KB Output is correct
104 Correct 828 ms 251056 KB Output is correct
105 Correct 909 ms 250976 KB Output is correct
106 Correct 916 ms 251036 KB Output is correct
107 Correct 905 ms 251060 KB Output is correct
108 Correct 933 ms 250920 KB Output is correct
109 Correct 878 ms 251060 KB Output is correct
110 Correct 862 ms 251056 KB Output is correct
111 Correct 888 ms 251064 KB Output is correct
112 Correct 906 ms 251060 KB Output is correct
113 Correct 881 ms 251064 KB Output is correct
114 Correct 887 ms 251056 KB Output is correct
115 Correct 895 ms 251056 KB Output is correct
116 Correct 888 ms 251056 KB Output is correct
117 Correct 922 ms 251060 KB Output is correct
118 Correct 910 ms 250836 KB Output is correct
119 Correct 908 ms 251036 KB Output is correct
120 Correct 0 ms 348 KB Output is correct
121 Correct 0 ms 348 KB Output is correct
122 Correct 1181 ms 250948 KB Output is correct
123 Correct 1256 ms 251060 KB Output is correct
124 Correct 1169 ms 251060 KB Output is correct
125 Correct 1157 ms 251052 KB Output is correct
126 Correct 1201 ms 250988 KB Output is correct
127 Correct 1166 ms 251060 KB Output is correct
128 Correct 1161 ms 251056 KB Output is correct
129 Correct 1192 ms 251056 KB Output is correct
130 Correct 1142 ms 251060 KB Output is correct
131 Correct 1212 ms 250904 KB Output is correct
132 Correct 1228 ms 250936 KB Output is correct
133 Correct 1163 ms 251060 KB Output is correct