답안 #64271

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64271 2018-08-03T20:24:28 Z reality Bulldozer (JOI17_bulldozer) C++17
100 / 100
1239 ms 50032 KB
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
struct fr {
    ll fi,se;
    fr(void) {
        fi = se = 0;
    }
    fr(ll aa,ll bb) {
        if (aa < 0 || (!aa && bb < 0))
            aa *= -1,bb *= -1;
        fi = aa;
        se = bb;
    }
};
bool operator == (fr a,fr b) {
    return a.fi * b.se == a.se * b.fi;
}
bool operator < (fr a,fr b) {
    return a.fi * b.se < a.se * b.fi;
}
bool operator != (fr a,fr b) {
    return !(a == b);
}
struct st {
    ll ss,ls,rs,as;
    st(void) {
        ss = ls = rs = as;
    }
    st(ll x) {
        ss = x;
        ls = rs = as = max(0ll,x);
    }
};
st operator + (st a,st b) {
    st c;
    c.ss = a.ss + b.ss;
    c.ls = max(a.ls,a.ss + b.ls);
    c.rs = max(b.rs,b.ss + a.rs);
    c.as = max({a.as,b.as,a.rs + b.ls});
    return c;
}
st t[4096];
void update(int l,int r,int pos,ll v,int node) {
    if (l == r)
        t[node] = st(v);
    else {
        int m = (l + r) / 2;
        if (pos <= m)
            update(l,m,pos,v,node * 2);
        else
            update(m+1,r,pos,v,node * 2 + 1);
        t[node] = t[node * 2] + t[node * 2 + 1];
    }
}
int main(void) {
    int n;
    cin>>n;
    vector < pair < pii , ll > > p(n);
    for (auto & it : p)
        cin>>it.fi.fi>>it.fi.se>>it.se;
    sort(all(p));
    vector < pair < fr , pii > > sw;
    for (int i = 0;i < n;++i)
        for (int j = i + 1;j < n;++j)
            sw.pb(mp(fr(p[i].fi.fi - p[j].fi.fi,p[i].fi.se - p[j].fi.se),mp(i,j)));
    vi q(n);
    for (int i = 0;i < n;++i)
        q[i] = i,update(0,n - 1,i,p[i].se,1);
    sort(all(sw),[&](auto a,auto b) {
            if (a.fi != b.fi)
                return a.fi < b.fi;
            return a.se < b.se;
        });
    int sz = sw.size();
    ll answer = t[1].as;
    for (int i = 0,j = 0;i < sz;i = j) {
        while (j < sz && sw[i].fi == sw[j].fi) {
            int pi = sw[j].se.fi;
            int pj = sw[j].se.se;
            swap(q[pi],q[pj]);
            update(0,n - 1,q[pi],p[pi].se,1);
            update(0,n - 1,q[pj],p[pj].se,1);
            ++j;
        }
        smax(answer,t[1].as);
    }
    cout << answer << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 4 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 768 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 4 ms 740 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 4 ms 768 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 432 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 3 ms 768 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 4 ms 740 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 3 ms 768 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 3 ms 768 KB Output is correct
29 Correct 4 ms 768 KB Output is correct
30 Correct 4 ms 768 KB Output is correct
31 Correct 4 ms 768 KB Output is correct
32 Correct 4 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 768 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 4 ms 740 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 4 ms 768 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 432 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 3 ms 768 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 4 ms 740 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 3 ms 768 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 3 ms 768 KB Output is correct
29 Correct 4 ms 768 KB Output is correct
30 Correct 4 ms 768 KB Output is correct
31 Correct 4 ms 768 KB Output is correct
32 Correct 4 ms 768 KB Output is correct
33 Correct 1112 ms 49840 KB Output is correct
34 Correct 1095 ms 49892 KB Output is correct
35 Correct 1109 ms 49860 KB Output is correct
36 Correct 1106 ms 49836 KB Output is correct
37 Correct 1101 ms 49836 KB Output is correct
38 Correct 1105 ms 49836 KB Output is correct
39 Correct 1126 ms 49836 KB Output is correct
40 Correct 1143 ms 49840 KB Output is correct
41 Correct 1092 ms 49836 KB Output is correct
42 Correct 1124 ms 49968 KB Output is correct
43 Correct 1106 ms 49860 KB Output is correct
44 Correct 1089 ms 49884 KB Output is correct
45 Correct 1096 ms 49864 KB Output is correct
46 Correct 1139 ms 49836 KB Output is correct
47 Correct 1106 ms 49836 KB Output is correct
48 Correct 1101 ms 49936 KB Output is correct
49 Correct 1088 ms 49964 KB Output is correct
50 Correct 1097 ms 49964 KB Output is correct
51 Correct 1125 ms 49860 KB Output is correct
52 Correct 1139 ms 49836 KB Output is correct
53 Correct 1130 ms 49836 KB Output is correct
54 Correct 1110 ms 49864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 768 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 4 ms 740 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 4 ms 768 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 432 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 3 ms 768 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 4 ms 740 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 3 ms 768 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 3 ms 768 KB Output is correct
29 Correct 4 ms 768 KB Output is correct
30 Correct 4 ms 768 KB Output is correct
31 Correct 4 ms 768 KB Output is correct
32 Correct 4 ms 768 KB Output is correct
33 Correct 1112 ms 49840 KB Output is correct
34 Correct 1095 ms 49892 KB Output is correct
35 Correct 1109 ms 49860 KB Output is correct
36 Correct 1106 ms 49836 KB Output is correct
37 Correct 1101 ms 49836 KB Output is correct
38 Correct 1105 ms 49836 KB Output is correct
39 Correct 1126 ms 49836 KB Output is correct
40 Correct 1143 ms 49840 KB Output is correct
41 Correct 1092 ms 49836 KB Output is correct
42 Correct 1124 ms 49968 KB Output is correct
43 Correct 1106 ms 49860 KB Output is correct
44 Correct 1089 ms 49884 KB Output is correct
45 Correct 1096 ms 49864 KB Output is correct
46 Correct 1139 ms 49836 KB Output is correct
47 Correct 1106 ms 49836 KB Output is correct
48 Correct 1101 ms 49936 KB Output is correct
49 Correct 1088 ms 49964 KB Output is correct
50 Correct 1097 ms 49964 KB Output is correct
51 Correct 1125 ms 49860 KB Output is correct
52 Correct 1139 ms 49836 KB Output is correct
53 Correct 1130 ms 49836 KB Output is correct
54 Correct 1110 ms 49864 KB Output is correct
55 Correct 1102 ms 49820 KB Output is correct
56 Correct 1097 ms 49832 KB Output is correct
57 Correct 1103 ms 49964 KB Output is correct
58 Correct 1113 ms 49888 KB Output is correct
59 Correct 1114 ms 49864 KB Output is correct
60 Correct 1170 ms 49884 KB Output is correct
61 Correct 1192 ms 49964 KB Output is correct
62 Correct 1133 ms 50032 KB Output is correct
63 Correct 1142 ms 50008 KB Output is correct
64 Correct 1141 ms 49896 KB Output is correct
65 Correct 1103 ms 49964 KB Output is correct
66 Correct 1125 ms 49836 KB Output is correct
67 Correct 1122 ms 49836 KB Output is correct
68 Correct 1130 ms 49836 KB Output is correct
69 Correct 1110 ms 49840 KB Output is correct
70 Correct 1143 ms 49836 KB Output is correct
71 Correct 1143 ms 49948 KB Output is correct
72 Correct 1129 ms 49840 KB Output is correct
73 Correct 1106 ms 49860 KB Output is correct
74 Correct 1135 ms 49840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 4 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 4 ms 740 KB Output is correct
19 Correct 4 ms 768 KB Output is correct
20 Correct 4 ms 768 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 4 ms 768 KB Output is correct
23 Correct 4 ms 768 KB Output is correct
24 Correct 4 ms 768 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 432 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 4 ms 768 KB Output is correct
37 Correct 3 ms 768 KB Output is correct
38 Correct 4 ms 724 KB Output is correct
39 Correct 4 ms 740 KB Output is correct
40 Correct 4 ms 768 KB Output is correct
41 Correct 3 ms 768 KB Output is correct
42 Correct 4 ms 768 KB Output is correct
43 Correct 3 ms 768 KB Output is correct
44 Correct 4 ms 768 KB Output is correct
45 Correct 4 ms 768 KB Output is correct
46 Correct 4 ms 768 KB Output is correct
47 Correct 4 ms 768 KB Output is correct
48 Correct 1112 ms 49840 KB Output is correct
49 Correct 1095 ms 49892 KB Output is correct
50 Correct 1109 ms 49860 KB Output is correct
51 Correct 1106 ms 49836 KB Output is correct
52 Correct 1101 ms 49836 KB Output is correct
53 Correct 1105 ms 49836 KB Output is correct
54 Correct 1126 ms 49836 KB Output is correct
55 Correct 1143 ms 49840 KB Output is correct
56 Correct 1092 ms 49836 KB Output is correct
57 Correct 1124 ms 49968 KB Output is correct
58 Correct 1106 ms 49860 KB Output is correct
59 Correct 1089 ms 49884 KB Output is correct
60 Correct 1096 ms 49864 KB Output is correct
61 Correct 1139 ms 49836 KB Output is correct
62 Correct 1106 ms 49836 KB Output is correct
63 Correct 1101 ms 49936 KB Output is correct
64 Correct 1088 ms 49964 KB Output is correct
65 Correct 1097 ms 49964 KB Output is correct
66 Correct 1125 ms 49860 KB Output is correct
67 Correct 1139 ms 49836 KB Output is correct
68 Correct 1130 ms 49836 KB Output is correct
69 Correct 1110 ms 49864 KB Output is correct
70 Correct 1102 ms 49820 KB Output is correct
71 Correct 1097 ms 49832 KB Output is correct
72 Correct 1103 ms 49964 KB Output is correct
73 Correct 1113 ms 49888 KB Output is correct
74 Correct 1114 ms 49864 KB Output is correct
75 Correct 1170 ms 49884 KB Output is correct
76 Correct 1192 ms 49964 KB Output is correct
77 Correct 1133 ms 50032 KB Output is correct
78 Correct 1142 ms 50008 KB Output is correct
79 Correct 1141 ms 49896 KB Output is correct
80 Correct 1103 ms 49964 KB Output is correct
81 Correct 1125 ms 49836 KB Output is correct
82 Correct 1122 ms 49836 KB Output is correct
83 Correct 1130 ms 49836 KB Output is correct
84 Correct 1110 ms 49840 KB Output is correct
85 Correct 1143 ms 49836 KB Output is correct
86 Correct 1143 ms 49948 KB Output is correct
87 Correct 1129 ms 49840 KB Output is correct
88 Correct 1106 ms 49860 KB Output is correct
89 Correct 1135 ms 49840 KB Output is correct
90 Correct 1149 ms 49808 KB Output is correct
91 Correct 1141 ms 49860 KB Output is correct
92 Correct 1239 ms 49836 KB Output is correct
93 Correct 1132 ms 49860 KB Output is correct
94 Correct 1095 ms 49880 KB Output is correct
95 Correct 1121 ms 49860 KB Output is correct
96 Correct 1232 ms 49836 KB Output is correct
97 Correct 1095 ms 49836 KB Output is correct
98 Correct 1090 ms 49836 KB Output is correct
99 Correct 1089 ms 49836 KB Output is correct
100 Correct 990 ms 49836 KB Output is correct
101 Correct 980 ms 49836 KB Output is correct
102 Correct 981 ms 49836 KB Output is correct
103 Correct 999 ms 49836 KB Output is correct
104 Correct 1030 ms 49836 KB Output is correct
105 Correct 1086 ms 49836 KB Output is correct
106 Correct 1052 ms 49912 KB Output is correct
107 Correct 1034 ms 49836 KB Output is correct
108 Correct 1079 ms 49836 KB Output is correct
109 Correct 1056 ms 49836 KB Output is correct
110 Correct 1094 ms 49976 KB Output is correct
111 Correct 1094 ms 49848 KB Output is correct
112 Correct 1105 ms 49832 KB Output is correct
113 Correct 1079 ms 49860 KB Output is correct
114 Correct 1190 ms 49840 KB Output is correct
115 Correct 1130 ms 49964 KB Output is correct
116 Correct 1094 ms 49836 KB Output is correct
117 Correct 1075 ms 49836 KB Output is correct
118 Correct 1076 ms 49804 KB Output is correct
119 Correct 1096 ms 50000 KB Output is correct
120 Correct 2 ms 384 KB Output is correct
121 Correct 2 ms 512 KB Output is correct
122 Correct 1162 ms 49872 KB Output is correct
123 Correct 1127 ms 49928 KB Output is correct
124 Correct 1181 ms 49836 KB Output is correct
125 Correct 1149 ms 49860 KB Output is correct
126 Correct 1129 ms 49836 KB Output is correct
127 Correct 1130 ms 49836 KB Output is correct
128 Correct 1100 ms 49904 KB Output is correct
129 Correct 1103 ms 49836 KB Output is correct
130 Correct 1106 ms 49840 KB Output is correct
131 Correct 1112 ms 49836 KB Output is correct
132 Correct 1119 ms 49860 KB Output is correct
133 Correct 1091 ms 49860 KB Output is correct