Submission #465226

# Submission time Handle Problem Language Result Execution time Memory
465226 2021-08-15T12:01:38 Z Vladth11 Bulldozer (JOI17_bulldozer) C++14
100 / 100
1202 ms 49904 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast,unroll-loops")
 
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST;
 
const ll NMAX = 2001;
const ll INF = (1LL << 60);
const ll HALF = (1LL << 59);
const ll MOD = 1000000007;
const ll BLOCK = 318;
const ll base = 31;
 
ll n;
 
class All{
public:
    struct Node{
        ll st, dr, total;
        ll ssm;
    };
    Node all[NMAX * 4];
    Node combine(Node a, Node b){
        Node rez;
        rez.st = max({a.st, a.total + b.st, 0LL});
        rez.dr = max({b.dr, b.total + a.dr, 0LL});
        rez.total = a.total + b.total;
        rez.ssm = max({a.ssm, b.ssm, a.dr + b.st, 0LL}); ///hmmm
        return rez;
    }
    void update(ll node, ll st, ll dr, ll a, ll b){
        if(st == dr){
          	//b = max(b, 0);
            all[node] = {max(b, 0LL), max(0LL, b), b, max(0LL, b)};
            return;
        }
        ll mid = (st + dr) / 2;
        if(a <= mid){
            update(node * 2, st, mid, a, b);
        }else{
            update(node * 2 + 1, mid + 1, dr, a, b);
        }
        all[node] = combine(all[node * 2], all[node * 2 + 1]);
    }
    Node best(){
        return all[1];
    }
}st;
 
struct poll{
    ll x, y, val, idx;
};
 
poll v[NMAX], a[NMAX];
map <pii, ll> mp;
 
struct event{
    pii p;
    double timp;
};
 
vector <event> events;
 
bool cmp(event a, event b){
    if(a.timp != b.timp)
        return a.timp < b.timp;
    if(a.p.second != b.p.second)
    return a.p.second < b.p.second;
    return a.p.first < b.p.first;
}
 
///De analizat
void swapElements(ll a, ll b){
    st.update(1, 1, n, v[a].idx, v[b].val);
    st.update(1, 1, n, v[b].idx, v[a].val);
    swap(v[a].idx, v[b].idx);
 
}
///De analizat
 
bool cmpp(poll a, poll b){
    if(a.x != b.x)
        return a.x > b.x;
    return a.y > b.y;
}
 
void compute(ll i, ll j){
    events.push_back({{i, j}, (double)(v[i].y - v[j].y) / (double)(v[i].x - v[j].x)});
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll i;
    cin >> n;
    for(i = 1; i <= n; i++){
        cin >> v[i].x >> v[i].y >> v[i].val;
    }
    sort(v + 1, v + n + 1, cmpp);
    for(i = 1; i <= n; i++){
        for(ll j = i + 1; j <= n; j++){
            compute(i, j);
        }
    }
    for(i = 1; i <= n; i++){
        st.update(1, 1, n, i, v[i].val);
        v[i].idx = i;
    }
    sort(events.begin(), events.end(), cmp);
    ll maxim = st.best().ssm;
    for(i = 0; i < events.size(); i++){
        swapElements(events[i].p.first, events[i].p.second);
        if(i < events.size() - 1 && events[i].timp == events[i + 1].timp){
            continue;
        }
        maxim = max(maxim, st.best().ssm);
    }
    cout << maxim;
    return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:120:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |     for(i = 0; i < events.size(); i++){
      |                ~~^~~~~~~~~~~~~~~
bulldozer.cpp:122:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |         if(i < events.size() - 1 && events[i].timp == events[i + 1].timp){
      |            ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 3 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 2 ms 544 KB Output is correct
28 Correct 3 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 3 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 2 ms 544 KB Output is correct
28 Correct 3 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 588 KB Output is correct
33 Correct 1185 ms 49720 KB Output is correct
34 Correct 1167 ms 49712 KB Output is correct
35 Correct 1160 ms 49760 KB Output is correct
36 Correct 1154 ms 49676 KB Output is correct
37 Correct 1145 ms 49656 KB Output is correct
38 Correct 1150 ms 49784 KB Output is correct
39 Correct 1145 ms 49680 KB Output is correct
40 Correct 1157 ms 49656 KB Output is correct
41 Correct 1156 ms 49712 KB Output is correct
42 Correct 1151 ms 49684 KB Output is correct
43 Correct 1151 ms 49768 KB Output is correct
44 Correct 1121 ms 49676 KB Output is correct
45 Correct 1155 ms 49652 KB Output is correct
46 Correct 1142 ms 49656 KB Output is correct
47 Correct 1145 ms 49808 KB Output is correct
48 Correct 1145 ms 49756 KB Output is correct
49 Correct 1139 ms 49904 KB Output is correct
50 Correct 1151 ms 49680 KB Output is correct
51 Correct 1151 ms 49656 KB Output is correct
52 Correct 1120 ms 49656 KB Output is correct
53 Correct 1149 ms 49812 KB Output is correct
54 Correct 1160 ms 49656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 3 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 2 ms 544 KB Output is correct
28 Correct 3 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 588 KB Output is correct
33 Correct 1185 ms 49720 KB Output is correct
34 Correct 1167 ms 49712 KB Output is correct
35 Correct 1160 ms 49760 KB Output is correct
36 Correct 1154 ms 49676 KB Output is correct
37 Correct 1145 ms 49656 KB Output is correct
38 Correct 1150 ms 49784 KB Output is correct
39 Correct 1145 ms 49680 KB Output is correct
40 Correct 1157 ms 49656 KB Output is correct
41 Correct 1156 ms 49712 KB Output is correct
42 Correct 1151 ms 49684 KB Output is correct
43 Correct 1151 ms 49768 KB Output is correct
44 Correct 1121 ms 49676 KB Output is correct
45 Correct 1155 ms 49652 KB Output is correct
46 Correct 1142 ms 49656 KB Output is correct
47 Correct 1145 ms 49808 KB Output is correct
48 Correct 1145 ms 49756 KB Output is correct
49 Correct 1139 ms 49904 KB Output is correct
50 Correct 1151 ms 49680 KB Output is correct
51 Correct 1151 ms 49656 KB Output is correct
52 Correct 1120 ms 49656 KB Output is correct
53 Correct 1149 ms 49812 KB Output is correct
54 Correct 1160 ms 49656 KB Output is correct
55 Correct 1136 ms 49680 KB Output is correct
56 Correct 1188 ms 49724 KB Output is correct
57 Correct 1143 ms 49656 KB Output is correct
58 Correct 1151 ms 49692 KB Output is correct
59 Correct 1186 ms 49680 KB Output is correct
60 Correct 1159 ms 49680 KB Output is correct
61 Correct 1174 ms 49772 KB Output is correct
62 Correct 1177 ms 49844 KB Output is correct
63 Correct 1174 ms 49736 KB Output is correct
64 Correct 1132 ms 49752 KB Output is correct
65 Correct 1138 ms 49684 KB Output is correct
66 Correct 1148 ms 49784 KB Output is correct
67 Correct 1148 ms 49808 KB Output is correct
68 Correct 1146 ms 49804 KB Output is correct
69 Correct 1164 ms 49848 KB Output is correct
70 Correct 1147 ms 49852 KB Output is correct
71 Correct 1140 ms 49788 KB Output is correct
72 Correct 1164 ms 49808 KB Output is correct
73 Correct 1173 ms 49840 KB Output is correct
74 Correct 1156 ms 49808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 3 ms 588 KB Output is correct
17 Correct 2 ms 588 KB Output is correct
18 Correct 2 ms 588 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 2 ms 588 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 2 ms 588 KB Output is correct
37 Correct 2 ms 588 KB Output is correct
38 Correct 2 ms 588 KB Output is correct
39 Correct 3 ms 588 KB Output is correct
40 Correct 2 ms 588 KB Output is correct
41 Correct 2 ms 588 KB Output is correct
42 Correct 2 ms 544 KB Output is correct
43 Correct 3 ms 588 KB Output is correct
44 Correct 2 ms 588 KB Output is correct
45 Correct 2 ms 588 KB Output is correct
46 Correct 2 ms 588 KB Output is correct
47 Correct 2 ms 588 KB Output is correct
48 Correct 1185 ms 49720 KB Output is correct
49 Correct 1167 ms 49712 KB Output is correct
50 Correct 1160 ms 49760 KB Output is correct
51 Correct 1154 ms 49676 KB Output is correct
52 Correct 1145 ms 49656 KB Output is correct
53 Correct 1150 ms 49784 KB Output is correct
54 Correct 1145 ms 49680 KB Output is correct
55 Correct 1157 ms 49656 KB Output is correct
56 Correct 1156 ms 49712 KB Output is correct
57 Correct 1151 ms 49684 KB Output is correct
58 Correct 1151 ms 49768 KB Output is correct
59 Correct 1121 ms 49676 KB Output is correct
60 Correct 1155 ms 49652 KB Output is correct
61 Correct 1142 ms 49656 KB Output is correct
62 Correct 1145 ms 49808 KB Output is correct
63 Correct 1145 ms 49756 KB Output is correct
64 Correct 1139 ms 49904 KB Output is correct
65 Correct 1151 ms 49680 KB Output is correct
66 Correct 1151 ms 49656 KB Output is correct
67 Correct 1120 ms 49656 KB Output is correct
68 Correct 1149 ms 49812 KB Output is correct
69 Correct 1160 ms 49656 KB Output is correct
70 Correct 1136 ms 49680 KB Output is correct
71 Correct 1188 ms 49724 KB Output is correct
72 Correct 1143 ms 49656 KB Output is correct
73 Correct 1151 ms 49692 KB Output is correct
74 Correct 1186 ms 49680 KB Output is correct
75 Correct 1159 ms 49680 KB Output is correct
76 Correct 1174 ms 49772 KB Output is correct
77 Correct 1177 ms 49844 KB Output is correct
78 Correct 1174 ms 49736 KB Output is correct
79 Correct 1132 ms 49752 KB Output is correct
80 Correct 1138 ms 49684 KB Output is correct
81 Correct 1148 ms 49784 KB Output is correct
82 Correct 1148 ms 49808 KB Output is correct
83 Correct 1146 ms 49804 KB Output is correct
84 Correct 1164 ms 49848 KB Output is correct
85 Correct 1147 ms 49852 KB Output is correct
86 Correct 1140 ms 49788 KB Output is correct
87 Correct 1164 ms 49808 KB Output is correct
88 Correct 1173 ms 49840 KB Output is correct
89 Correct 1156 ms 49808 KB Output is correct
90 Correct 1133 ms 49736 KB Output is correct
91 Correct 1140 ms 49772 KB Output is correct
92 Correct 1202 ms 49820 KB Output is correct
93 Correct 1156 ms 49856 KB Output is correct
94 Correct 1141 ms 49808 KB Output is correct
95 Correct 1196 ms 49852 KB Output is correct
96 Correct 1174 ms 49812 KB Output is correct
97 Correct 1185 ms 49808 KB Output is correct
98 Correct 1139 ms 49820 KB Output is correct
99 Correct 1155 ms 49820 KB Output is correct
100 Correct 998 ms 49784 KB Output is correct
101 Correct 984 ms 49812 KB Output is correct
102 Correct 992 ms 49832 KB Output is correct
103 Correct 1002 ms 49864 KB Output is correct
104 Correct 987 ms 49824 KB Output is correct
105 Correct 1036 ms 49796 KB Output is correct
106 Correct 1034 ms 49832 KB Output is correct
107 Correct 1006 ms 49808 KB Output is correct
108 Correct 1022 ms 49780 KB Output is correct
109 Correct 1018 ms 49808 KB Output is correct
110 Correct 1071 ms 49796 KB Output is correct
111 Correct 1083 ms 49784 KB Output is correct
112 Correct 1054 ms 49816 KB Output is correct
113 Correct 1067 ms 49780 KB Output is correct
114 Correct 1057 ms 49800 KB Output is correct
115 Correct 1068 ms 49784 KB Output is correct
116 Correct 1081 ms 49840 KB Output is correct
117 Correct 1064 ms 49820 KB Output is correct
118 Correct 1058 ms 49828 KB Output is correct
119 Correct 1085 ms 49740 KB Output is correct
120 Correct 1 ms 332 KB Output is correct
121 Correct 1 ms 332 KB Output is correct
122 Correct 1145 ms 49796 KB Output is correct
123 Correct 1168 ms 49808 KB Output is correct
124 Correct 1162 ms 49812 KB Output is correct
125 Correct 1162 ms 49752 KB Output is correct
126 Correct 1136 ms 49780 KB Output is correct
127 Correct 1178 ms 49832 KB Output is correct
128 Correct 1147 ms 49844 KB Output is correct
129 Correct 1174 ms 49784 KB Output is correct
130 Correct 1146 ms 49808 KB Output is correct
131 Correct 1133 ms 49808 KB Output is correct
132 Correct 1122 ms 49844 KB Output is correct
133 Correct 1135 ms 49832 KB Output is correct