답안 #122053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
122053 2019-06-27T13:20:01 Z egorlifar Bulldozer (JOI17_bulldozer) C++17
100 / 100
1373 ms 32452 KB
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <chrono>
 
using namespace std;

template<class T1, class T2> inline int chkmin(T1 &x, const T2 &y) {
    if (x > y) {
        x = y;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T1, class T2> inline int chkmax(T1 &x, const T2 &y) {
    if (x < y) {
        x = y;
        return 1;
    }
    else {
        return 0;
    }
}

#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define mp make_pair
#define pb push_back
#define read(FILENAME) freopen((string(FILENAME) + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((string(FILENAME) + ".out").c_str(), "w", stdout);

template<class iterator> void output(iterator begin, iterator end, ostream &out = cerr) {
    while (begin != end) {
        out << (*begin) << " ";
        begin++;
    }
    out << endl;
}


template<class T> void output(const T &x, ostream &out = cerr) {
    output(x.begin(), x.end(), out);
}

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0); 
}
const int MAXN = 3005;


struct point
{
    int x, y, w;
    point(){}
    point(int _x, int _y) {
        x = _x;
        y = _y;
    }
};


bool operator <(const point &a, const point &b) {
    return a.x < b.x || (a.x == b.x && a.y < b.y);
}


point operator -(const point &a, const point &b) {
    return point(a.x - b.x, a.y - b.y);
}


long long vec(const point &a, const point &b) {
    return 1LL * a.x * b.y - 1LL * a.y * b.x;
}


int n;
point p[MAXN];
int pos[MAXN];


long long comp(pair<int, int> a, pair<int, int> b) {
    point g = p[a.second] - p[a.first];
    point g1 = p[b.second] - p[b.first];
    return vec(g, g1);
}


long long comp1(pair<int, int> a, pair<int, int> b) {
    long long ft = comp(a, b);
    if (ft != 0) {
        return ft < 0;
    } else {
        return a < b;
    }
}


struct node {
    long long sum, pref, suf, val;
    node(int x = 0) {
      sum = (long long) x;
      pref = suf = val = (long long)max(x, 0);
    };
    friend node operator + (const node &l, const node &r) {
        node ans;
        ans.sum = l.sum + r.sum;
        ans.pref = max(l.pref, l.sum + r.pref);
        ans.suf = max(r.suf, r.sum + l.suf);
        ans.val = max({l.val, r.val, l.suf + r.pref});
        return ans;
   }
};
 

node t[MAXN * 2]; 

 
void modify(int v, int l, int r, int pos, int val) {
    if (l == r) {
        t[v] = node(val);
        return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid) {
        modify(v << 1, l, mid, pos, val);
    } else {
        modify(v << 1 | 1, mid + 1, r, pos, val);
    }
    t[v] = t[v << 1] + t[v << 1 | 1];
}

int main() {
    fast_io();
    //read("input");
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i].x >> p[i].y >> p[i].w;  
    }
    sort(p + 1, p + n + 1);
    vector<pair<int, int> > st;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            st.pb({i, j});
        }
    }
    sort(all(st), comp1);
    for (int i = 1; i <= n; i++) {
        pos[i] = i;
        modify(1, 1, n, i, p[i].w);
    }
    long long ans = t[1].val;
    int i = 0;
    while (i < sz(st)) {
        vector<pair<int, int> > kek;
        kek.pb(st[i]);
        while (i + 1 < sz(st) && !comp(st[i], st[i + 1])) {
            i++;
            kek.pb(st[i]);
        }
        for (auto x: kek) {
            int a = x.first;
            int b = x.second;
            swap(pos[a], pos[b]);
            modify(1, 1, n, pos[a], p[a].w);
            modify(1, 1, n, pos[b], p[b].w);
        }
        chkmax(ans, t[1].val);
        i++;
    }
    cout << ans << '\n';
    return 0;
}   
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 14 ms 768 KB Output is correct
3 Correct 4 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 3 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 4 ms 640 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 4 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 512 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 512 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 13 ms 768 KB Output is correct
24 Correct 4 ms 640 KB Output is correct
25 Correct 4 ms 640 KB Output is correct
26 Correct 4 ms 640 KB Output is correct
27 Correct 4 ms 640 KB Output is correct
28 Correct 4 ms 640 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 4 ms 640 KB Output is correct
31 Correct 4 ms 640 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 4 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 512 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 512 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 13 ms 768 KB Output is correct
24 Correct 4 ms 640 KB Output is correct
25 Correct 4 ms 640 KB Output is correct
26 Correct 4 ms 640 KB Output is correct
27 Correct 4 ms 640 KB Output is correct
28 Correct 4 ms 640 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 4 ms 640 KB Output is correct
31 Correct 4 ms 640 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
33 Correct 1217 ms 17124 KB Output is correct
34 Correct 1226 ms 17132 KB Output is correct
35 Correct 1163 ms 17132 KB Output is correct
36 Correct 1165 ms 17132 KB Output is correct
37 Correct 1184 ms 17132 KB Output is correct
38 Correct 1162 ms 17132 KB Output is correct
39 Correct 1182 ms 17120 KB Output is correct
40 Correct 1152 ms 17132 KB Output is correct
41 Correct 1169 ms 17132 KB Output is correct
42 Correct 1189 ms 17132 KB Output is correct
43 Correct 1213 ms 17132 KB Output is correct
44 Correct 1146 ms 17120 KB Output is correct
45 Correct 1140 ms 17132 KB Output is correct
46 Correct 1200 ms 17132 KB Output is correct
47 Correct 1154 ms 17132 KB Output is correct
48 Correct 1152 ms 17132 KB Output is correct
49 Correct 1174 ms 17244 KB Output is correct
50 Correct 1182 ms 17096 KB Output is correct
51 Correct 1167 ms 17132 KB Output is correct
52 Correct 1233 ms 17124 KB Output is correct
53 Correct 1173 ms 17132 KB Output is correct
54 Correct 1148 ms 17132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 4 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 512 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 512 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 13 ms 768 KB Output is correct
24 Correct 4 ms 640 KB Output is correct
25 Correct 4 ms 640 KB Output is correct
26 Correct 4 ms 640 KB Output is correct
27 Correct 4 ms 640 KB Output is correct
28 Correct 4 ms 640 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 4 ms 640 KB Output is correct
31 Correct 4 ms 640 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
33 Correct 1217 ms 17124 KB Output is correct
34 Correct 1226 ms 17132 KB Output is correct
35 Correct 1163 ms 17132 KB Output is correct
36 Correct 1165 ms 17132 KB Output is correct
37 Correct 1184 ms 17132 KB Output is correct
38 Correct 1162 ms 17132 KB Output is correct
39 Correct 1182 ms 17120 KB Output is correct
40 Correct 1152 ms 17132 KB Output is correct
41 Correct 1169 ms 17132 KB Output is correct
42 Correct 1189 ms 17132 KB Output is correct
43 Correct 1213 ms 17132 KB Output is correct
44 Correct 1146 ms 17120 KB Output is correct
45 Correct 1140 ms 17132 KB Output is correct
46 Correct 1200 ms 17132 KB Output is correct
47 Correct 1154 ms 17132 KB Output is correct
48 Correct 1152 ms 17132 KB Output is correct
49 Correct 1174 ms 17244 KB Output is correct
50 Correct 1182 ms 17096 KB Output is correct
51 Correct 1167 ms 17132 KB Output is correct
52 Correct 1233 ms 17124 KB Output is correct
53 Correct 1173 ms 17132 KB Output is correct
54 Correct 1148 ms 17132 KB Output is correct
55 Correct 1164 ms 17132 KB Output is correct
56 Correct 1178 ms 17124 KB Output is correct
57 Correct 1181 ms 17132 KB Output is correct
58 Correct 1202 ms 17132 KB Output is correct
59 Correct 1179 ms 17132 KB Output is correct
60 Correct 1169 ms 17132 KB Output is correct
61 Correct 1270 ms 17388 KB Output is correct
62 Correct 1207 ms 17132 KB Output is correct
63 Correct 1161 ms 17124 KB Output is correct
64 Correct 1163 ms 17124 KB Output is correct
65 Correct 1143 ms 17120 KB Output is correct
66 Correct 1154 ms 17380 KB Output is correct
67 Correct 1283 ms 17260 KB Output is correct
68 Correct 1178 ms 17124 KB Output is correct
69 Correct 1193 ms 17132 KB Output is correct
70 Correct 1161 ms 17132 KB Output is correct
71 Correct 1191 ms 17132 KB Output is correct
72 Correct 1217 ms 17132 KB Output is correct
73 Correct 1250 ms 17252 KB Output is correct
74 Correct 1153 ms 17124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 14 ms 768 KB Output is correct
3 Correct 4 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 3 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 4 ms 640 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 4 ms 640 KB Output is correct
17 Correct 4 ms 640 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 4 ms 640 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 4 ms 640 KB Output is correct
24 Correct 5 ms 640 KB Output is correct
25 Correct 4 ms 640 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 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 512 KB Output is correct
36 Correct 4 ms 640 KB Output is correct
37 Correct 4 ms 640 KB Output is correct
38 Correct 13 ms 768 KB Output is correct
39 Correct 4 ms 640 KB Output is correct
40 Correct 4 ms 640 KB Output is correct
41 Correct 4 ms 640 KB Output is correct
42 Correct 4 ms 640 KB Output is correct
43 Correct 4 ms 640 KB Output is correct
44 Correct 4 ms 640 KB Output is correct
45 Correct 4 ms 640 KB Output is correct
46 Correct 4 ms 640 KB Output is correct
47 Correct 4 ms 640 KB Output is correct
48 Correct 1217 ms 17124 KB Output is correct
49 Correct 1226 ms 17132 KB Output is correct
50 Correct 1163 ms 17132 KB Output is correct
51 Correct 1165 ms 17132 KB Output is correct
52 Correct 1184 ms 17132 KB Output is correct
53 Correct 1162 ms 17132 KB Output is correct
54 Correct 1182 ms 17120 KB Output is correct
55 Correct 1152 ms 17132 KB Output is correct
56 Correct 1169 ms 17132 KB Output is correct
57 Correct 1189 ms 17132 KB Output is correct
58 Correct 1213 ms 17132 KB Output is correct
59 Correct 1146 ms 17120 KB Output is correct
60 Correct 1140 ms 17132 KB Output is correct
61 Correct 1200 ms 17132 KB Output is correct
62 Correct 1154 ms 17132 KB Output is correct
63 Correct 1152 ms 17132 KB Output is correct
64 Correct 1174 ms 17244 KB Output is correct
65 Correct 1182 ms 17096 KB Output is correct
66 Correct 1167 ms 17132 KB Output is correct
67 Correct 1233 ms 17124 KB Output is correct
68 Correct 1173 ms 17132 KB Output is correct
69 Correct 1148 ms 17132 KB Output is correct
70 Correct 1164 ms 17132 KB Output is correct
71 Correct 1178 ms 17124 KB Output is correct
72 Correct 1181 ms 17132 KB Output is correct
73 Correct 1202 ms 17132 KB Output is correct
74 Correct 1179 ms 17132 KB Output is correct
75 Correct 1169 ms 17132 KB Output is correct
76 Correct 1270 ms 17388 KB Output is correct
77 Correct 1207 ms 17132 KB Output is correct
78 Correct 1161 ms 17124 KB Output is correct
79 Correct 1163 ms 17124 KB Output is correct
80 Correct 1143 ms 17120 KB Output is correct
81 Correct 1154 ms 17380 KB Output is correct
82 Correct 1283 ms 17260 KB Output is correct
83 Correct 1178 ms 17124 KB Output is correct
84 Correct 1193 ms 17132 KB Output is correct
85 Correct 1161 ms 17132 KB Output is correct
86 Correct 1191 ms 17132 KB Output is correct
87 Correct 1217 ms 17132 KB Output is correct
88 Correct 1250 ms 17252 KB Output is correct
89 Correct 1153 ms 17124 KB Output is correct
90 Correct 1237 ms 17260 KB Output is correct
91 Correct 1373 ms 17248 KB Output is correct
92 Correct 1176 ms 17124 KB Output is correct
93 Correct 1162 ms 17124 KB Output is correct
94 Correct 1175 ms 17132 KB Output is correct
95 Correct 1171 ms 17124 KB Output is correct
96 Correct 1171 ms 17132 KB Output is correct
97 Correct 1160 ms 17180 KB Output is correct
98 Correct 1205 ms 17244 KB Output is correct
99 Correct 1180 ms 17120 KB Output is correct
100 Correct 1025 ms 32324 KB Output is correct
101 Correct 1025 ms 32432 KB Output is correct
102 Correct 1016 ms 32416 KB Output is correct
103 Correct 1216 ms 32452 KB Output is correct
104 Correct 1022 ms 32440 KB Output is correct
105 Correct 1072 ms 29660 KB Output is correct
106 Correct 1052 ms 29760 KB Output is correct
107 Correct 1049 ms 29780 KB Output is correct
108 Correct 1083 ms 29784 KB Output is correct
109 Correct 1073 ms 29888 KB Output is correct
110 Correct 1045 ms 17252 KB Output is correct
111 Correct 1077 ms 17116 KB Output is correct
112 Correct 1067 ms 17132 KB Output is correct
113 Correct 1109 ms 17124 KB Output is correct
114 Correct 1077 ms 17124 KB Output is correct
115 Correct 1108 ms 17124 KB Output is correct
116 Correct 1067 ms 17124 KB Output is correct
117 Correct 1053 ms 17120 KB Output is correct
118 Correct 1075 ms 17132 KB Output is correct
119 Correct 1057 ms 17260 KB Output is correct
120 Correct 3 ms 512 KB Output is correct
121 Correct 2 ms 512 KB Output is correct
122 Correct 1189 ms 17132 KB Output is correct
123 Correct 1201 ms 17260 KB Output is correct
124 Correct 1176 ms 17260 KB Output is correct
125 Correct 1221 ms 17288 KB Output is correct
126 Correct 1175 ms 17252 KB Output is correct
127 Correct 1168 ms 17244 KB Output is correct
128 Correct 1163 ms 17132 KB Output is correct
129 Correct 1166 ms 17132 KB Output is correct
130 Correct 1179 ms 17124 KB Output is correct
131 Correct 1165 ms 17132 KB Output is correct
132 Correct 1179 ms 17280 KB Output is correct
133 Correct 1166 ms 17132 KB Output is correct