Submission #229418

# Submission time Handle Problem Language Result Execution time Memory
229418 2020-05-04T12:22:41 Z fedoseevtimofey Bulldozer (JOI17_bulldozer) C++14
100 / 100
1152 ms 33928 KB
#include <iostream>	
#include <string>	
#include <vector>	
#include <queue>	
#include <deque>	
#include <stack>	
#include <set>	
#include <map>	
#include <unordered_map>	
#include <unordered_set>	
#include <cstring>	
#include <cmath>	
#include <cstdlib>	
#include <algorithm>	
#include <random>	
#include <iomanip>	
#include <functional>	
#include <cassert>	
 	
using namespace std;	
 	
typedef long long ll;	
 	
struct point {	
  int x, y;	
  point(int x, int y) : x(x), y(y) {}	
  point(int x) : x(x), y(x) {}	
  point() : x(0), y(0) {}	
  point operator -(const point &p) const {	
    return point(x - p.x, y - p.y);	
  }	
  ll operator *(const point &p) const {	
    return (ll)x * p.y - (ll)y * p.x;	
  }	
  int type() const {	
    return y > 0 || (y == 0 && x > 0);	
  }	
  bool operator ==(const point &p) const {	
    return x == p.x && y == p.y;	
  }	
};	
 
bool operator <(const point &a, const point &b) {	
  if (a.type() != b.type()) {	
    return a.type() > b.type();	
  }	
  return a * b > 0;	
}	
 	
const ll Inf = 1e18;	
 	
struct Node {	
  ll sum, best, max_pref, max_suf;	
  Node() {	
    sum = 0;	
    best = 0 ;	
    max_pref = max_suf = -Inf;	
  }	
  Node(ll x) {	
    sum = x;	
    best = max(x, 0LL);	
    max_pref = max(0LL, x);	
    max_suf = max(0LL, x);	
  }	
  Node operator +(const Node &other) const {	
    Node res;	
    res.best = max(best, other.best);	
    res.best = max(res.best, max_suf + other.max_pref);	
    res.sum = sum + other.sum;	
    res.max_pref = max(max_pref, sum + other.max_pref);	
    res.max_suf = max(other.max_suf, other.sum + max_suf);	
    return res;	
  }	
};	
 	
const int N = 4096;	
Node t[2 * N];	
 	
int n;	
 	
void modify(int id, ll val) {	
  t[N + id] = Node(val);	
  for (int v = (N + id) / 2; v >= 1; v /= 2) {	
    t[v] = t[2 * v] + t[2 * v + 1];	
  }	
}	
 
int main() {	
  ios_base::sync_with_stdio(false); cin.tie(0);	
#ifdef LOCAL	
  freopen("input.txt", "r", stdin);	
#endif	
  cin >> n;	
  map <pair <int, int>, ll> cost;	
  for (int i = 0; i < n; ++i) {	
    int x, y, w;	
    cin >> x >> y >> w;	
    cost[{x, y}] += w;	
  }	
  n = cost.size();	
  vector <point> a(n); vector <int> w(n);	
  {	
    int id = 0;	
    for (auto it = cost.begin(); it != cost.end(); ++it, ++id) {	
      a[id] = point((it->first).first, (it->first).second);	
      w[id] = it->second;	
    }	
  }	
  vector <int> p(n);
  iota(p.begin(), p.end(), 0);	
  sort(p.begin(), p.end(), [&] (int i, int j) {	
    if (a[i].y != a[j].y) return a[i].y < a[j].y;	
    return a[i].x > a[j].x;	
  });	
 
  vector <int> pos(n);	
  for (int i = 0; i < n; ++i) pos[p[i]] = i;	
  vector <pair <point, pair <int, int>>> dir;	
  for (int i = 0; i < n; ++i) {	
    for (int j = i + 1; j < n; ++j) {	
      if (pos[i] > pos[j]) dir.emplace_back(a[i] - a[j], make_pair(i, j));	
      else dir.emplace_back(a[j] - a[i], make_pair(i, j));
    }	
  }	
  sort(dir.begin(), dir.end());	
  for (int i = 0; i < n; ++i) {	
    modify(pos[i], w[i]);	
  }	
  ll ans = t[1].best;	
  point lst; bool fnd = false;
  for (auto d : dir) {	
    int i = d.second.first, j = d.second.second;	
    modify(pos[i], w[j]);	
    modify(pos[j], w[i]);	
    swap(pos[i], pos[j]);	
    if (fnd && lst < d.first) ans = max(ans, t[1].best);	
    fnd = true;
    lst = d.first;
  }	
 	
  cout << ans << '\n';	
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 768 KB Output is correct
2 Correct 8 ms 768 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 9 ms 768 KB Output is correct
5 Correct 7 ms 896 KB Output is correct
6 Correct 9 ms 768 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 7 ms 768 KB Output is correct
9 Correct 7 ms 768 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 768 KB Output is correct
2 Correct 7 ms 816 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 7 ms 768 KB Output is correct
5 Correct 7 ms 768 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 7 ms 768 KB Output is correct
9 Correct 7 ms 896 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 5 ms 640 KB Output is correct
18 Correct 5 ms 640 KB Output is correct
19 Correct 5 ms 640 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 7 ms 768 KB Output is correct
23 Correct 7 ms 896 KB Output is correct
24 Correct 7 ms 768 KB Output is correct
25 Correct 7 ms 768 KB Output is correct
26 Correct 7 ms 768 KB Output is correct
27 Correct 7 ms 820 KB Output is correct
28 Correct 8 ms 768 KB Output is correct
29 Correct 7 ms 768 KB Output is correct
30 Correct 8 ms 768 KB Output is correct
31 Correct 7 ms 768 KB Output is correct
32 Correct 7 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 768 KB Output is correct
2 Correct 7 ms 816 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 7 ms 768 KB Output is correct
5 Correct 7 ms 768 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 7 ms 768 KB Output is correct
9 Correct 7 ms 896 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 5 ms 640 KB Output is correct
18 Correct 5 ms 640 KB Output is correct
19 Correct 5 ms 640 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 7 ms 768 KB Output is correct
23 Correct 7 ms 896 KB Output is correct
24 Correct 7 ms 768 KB Output is correct
25 Correct 7 ms 768 KB Output is correct
26 Correct 7 ms 768 KB Output is correct
27 Correct 7 ms 820 KB Output is correct
28 Correct 8 ms 768 KB Output is correct
29 Correct 7 ms 768 KB Output is correct
30 Correct 8 ms 768 KB Output is correct
31 Correct 7 ms 768 KB Output is correct
32 Correct 7 ms 768 KB Output is correct
33 Correct 1076 ms 33728 KB Output is correct
34 Correct 1075 ms 33752 KB Output is correct
35 Correct 1042 ms 33744 KB Output is correct
36 Correct 1046 ms 33880 KB Output is correct
37 Correct 1064 ms 33760 KB Output is correct
38 Correct 1024 ms 33744 KB Output is correct
39 Correct 1043 ms 33728 KB Output is correct
40 Correct 1033 ms 33760 KB Output is correct
41 Correct 1094 ms 33728 KB Output is correct
42 Correct 1048 ms 33872 KB Output is correct
43 Correct 1152 ms 33728 KB Output is correct
44 Correct 1056 ms 33744 KB Output is correct
45 Correct 1069 ms 33768 KB Output is correct
46 Correct 1089 ms 33744 KB Output is correct
47 Correct 1073 ms 33728 KB Output is correct
48 Correct 1037 ms 33744 KB Output is correct
49 Correct 1096 ms 33744 KB Output is correct
50 Correct 1080 ms 33768 KB Output is correct
51 Correct 1073 ms 33740 KB Output is correct
52 Correct 1072 ms 33744 KB Output is correct
53 Correct 1048 ms 33760 KB Output is correct
54 Correct 1047 ms 33752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 768 KB Output is correct
2 Correct 7 ms 816 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 7 ms 768 KB Output is correct
5 Correct 7 ms 768 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 7 ms 768 KB Output is correct
9 Correct 7 ms 896 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 5 ms 640 KB Output is correct
18 Correct 5 ms 640 KB Output is correct
19 Correct 5 ms 640 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 7 ms 768 KB Output is correct
23 Correct 7 ms 896 KB Output is correct
24 Correct 7 ms 768 KB Output is correct
25 Correct 7 ms 768 KB Output is correct
26 Correct 7 ms 768 KB Output is correct
27 Correct 7 ms 820 KB Output is correct
28 Correct 8 ms 768 KB Output is correct
29 Correct 7 ms 768 KB Output is correct
30 Correct 8 ms 768 KB Output is correct
31 Correct 7 ms 768 KB Output is correct
32 Correct 7 ms 768 KB Output is correct
33 Correct 1076 ms 33728 KB Output is correct
34 Correct 1075 ms 33752 KB Output is correct
35 Correct 1042 ms 33744 KB Output is correct
36 Correct 1046 ms 33880 KB Output is correct
37 Correct 1064 ms 33760 KB Output is correct
38 Correct 1024 ms 33744 KB Output is correct
39 Correct 1043 ms 33728 KB Output is correct
40 Correct 1033 ms 33760 KB Output is correct
41 Correct 1094 ms 33728 KB Output is correct
42 Correct 1048 ms 33872 KB Output is correct
43 Correct 1152 ms 33728 KB Output is correct
44 Correct 1056 ms 33744 KB Output is correct
45 Correct 1069 ms 33768 KB Output is correct
46 Correct 1089 ms 33744 KB Output is correct
47 Correct 1073 ms 33728 KB Output is correct
48 Correct 1037 ms 33744 KB Output is correct
49 Correct 1096 ms 33744 KB Output is correct
50 Correct 1080 ms 33768 KB Output is correct
51 Correct 1073 ms 33740 KB Output is correct
52 Correct 1072 ms 33744 KB Output is correct
53 Correct 1048 ms 33760 KB Output is correct
54 Correct 1047 ms 33752 KB Output is correct
55 Correct 1086 ms 33768 KB Output is correct
56 Correct 1051 ms 33768 KB Output is correct
57 Correct 1105 ms 33744 KB Output is correct
58 Correct 1055 ms 33760 KB Output is correct
59 Correct 1041 ms 33616 KB Output is correct
60 Correct 1060 ms 33748 KB Output is correct
61 Correct 1070 ms 33768 KB Output is correct
62 Correct 1089 ms 33756 KB Output is correct
63 Correct 1053 ms 33760 KB Output is correct
64 Correct 1066 ms 33760 KB Output is correct
65 Correct 1043 ms 33744 KB Output is correct
66 Correct 1067 ms 33928 KB Output is correct
67 Correct 1069 ms 33744 KB Output is correct
68 Correct 1059 ms 33768 KB Output is correct
69 Correct 1074 ms 33744 KB Output is correct
70 Correct 1069 ms 33768 KB Output is correct
71 Correct 1093 ms 33756 KB Output is correct
72 Correct 1044 ms 33728 KB Output is correct
73 Correct 1049 ms 33732 KB Output is correct
74 Correct 1043 ms 33744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 768 KB Output is correct
2 Correct 8 ms 768 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 9 ms 768 KB Output is correct
5 Correct 7 ms 896 KB Output is correct
6 Correct 9 ms 768 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 7 ms 768 KB Output is correct
9 Correct 7 ms 768 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 696 KB Output is correct
16 Correct 7 ms 768 KB Output is correct
17 Correct 7 ms 816 KB Output is correct
18 Correct 7 ms 768 KB Output is correct
19 Correct 7 ms 768 KB Output is correct
20 Correct 7 ms 768 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 7 ms 768 KB Output is correct
23 Correct 7 ms 768 KB Output is correct
24 Correct 7 ms 896 KB Output is correct
25 Correct 7 ms 768 KB Output is correct
26 Correct 5 ms 640 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 5 ms 640 KB Output is correct
29 Correct 5 ms 640 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 640 KB Output is correct
32 Correct 5 ms 640 KB Output is correct
33 Correct 5 ms 640 KB Output is correct
34 Correct 5 ms 640 KB Output is correct
35 Correct 5 ms 640 KB Output is correct
36 Correct 7 ms 768 KB Output is correct
37 Correct 7 ms 768 KB Output is correct
38 Correct 7 ms 896 KB Output is correct
39 Correct 7 ms 768 KB Output is correct
40 Correct 7 ms 768 KB Output is correct
41 Correct 7 ms 768 KB Output is correct
42 Correct 7 ms 820 KB Output is correct
43 Correct 8 ms 768 KB Output is correct
44 Correct 7 ms 768 KB Output is correct
45 Correct 8 ms 768 KB Output is correct
46 Correct 7 ms 768 KB Output is correct
47 Correct 7 ms 768 KB Output is correct
48 Correct 1076 ms 33728 KB Output is correct
49 Correct 1075 ms 33752 KB Output is correct
50 Correct 1042 ms 33744 KB Output is correct
51 Correct 1046 ms 33880 KB Output is correct
52 Correct 1064 ms 33760 KB Output is correct
53 Correct 1024 ms 33744 KB Output is correct
54 Correct 1043 ms 33728 KB Output is correct
55 Correct 1033 ms 33760 KB Output is correct
56 Correct 1094 ms 33728 KB Output is correct
57 Correct 1048 ms 33872 KB Output is correct
58 Correct 1152 ms 33728 KB Output is correct
59 Correct 1056 ms 33744 KB Output is correct
60 Correct 1069 ms 33768 KB Output is correct
61 Correct 1089 ms 33744 KB Output is correct
62 Correct 1073 ms 33728 KB Output is correct
63 Correct 1037 ms 33744 KB Output is correct
64 Correct 1096 ms 33744 KB Output is correct
65 Correct 1080 ms 33768 KB Output is correct
66 Correct 1073 ms 33740 KB Output is correct
67 Correct 1072 ms 33744 KB Output is correct
68 Correct 1048 ms 33760 KB Output is correct
69 Correct 1047 ms 33752 KB Output is correct
70 Correct 1086 ms 33768 KB Output is correct
71 Correct 1051 ms 33768 KB Output is correct
72 Correct 1105 ms 33744 KB Output is correct
73 Correct 1055 ms 33760 KB Output is correct
74 Correct 1041 ms 33616 KB Output is correct
75 Correct 1060 ms 33748 KB Output is correct
76 Correct 1070 ms 33768 KB Output is correct
77 Correct 1089 ms 33756 KB Output is correct
78 Correct 1053 ms 33760 KB Output is correct
79 Correct 1066 ms 33760 KB Output is correct
80 Correct 1043 ms 33744 KB Output is correct
81 Correct 1067 ms 33928 KB Output is correct
82 Correct 1069 ms 33744 KB Output is correct
83 Correct 1059 ms 33768 KB Output is correct
84 Correct 1074 ms 33744 KB Output is correct
85 Correct 1069 ms 33768 KB Output is correct
86 Correct 1093 ms 33756 KB Output is correct
87 Correct 1044 ms 33728 KB Output is correct
88 Correct 1049 ms 33732 KB Output is correct
89 Correct 1043 ms 33744 KB Output is correct
90 Correct 1044 ms 33744 KB Output is correct
91 Correct 1046 ms 33744 KB Output is correct
92 Correct 1047 ms 33760 KB Output is correct
93 Correct 1039 ms 33744 KB Output is correct
94 Correct 1058 ms 33908 KB Output is correct
95 Correct 1051 ms 33752 KB Output is correct
96 Correct 1050 ms 33888 KB Output is correct
97 Correct 1051 ms 33752 KB Output is correct
98 Correct 1051 ms 33876 KB Output is correct
99 Correct 1083 ms 33744 KB Output is correct
100 Correct 969 ms 33744 KB Output is correct
101 Correct 965 ms 33872 KB Output is correct
102 Correct 982 ms 33760 KB Output is correct
103 Correct 968 ms 33728 KB Output is correct
104 Correct 984 ms 33768 KB Output is correct
105 Correct 969 ms 33748 KB Output is correct
106 Correct 966 ms 33760 KB Output is correct
107 Correct 1002 ms 33744 KB Output is correct
108 Correct 974 ms 33748 KB Output is correct
109 Correct 988 ms 33868 KB Output is correct
110 Correct 1022 ms 33744 KB Output is correct
111 Correct 1004 ms 33732 KB Output is correct
112 Correct 1006 ms 33768 KB Output is correct
113 Correct 1014 ms 33760 KB Output is correct
114 Correct 1010 ms 33760 KB Output is correct
115 Correct 1000 ms 33744 KB Output is correct
116 Correct 1014 ms 33868 KB Output is correct
117 Correct 1002 ms 33916 KB Output is correct
118 Correct 1022 ms 33744 KB Output is correct
119 Correct 1010 ms 33744 KB Output is correct
120 Correct 5 ms 640 KB Output is correct
121 Correct 5 ms 640 KB Output is correct
122 Correct 1056 ms 33744 KB Output is correct
123 Correct 1035 ms 33752 KB Output is correct
124 Correct 1042 ms 33740 KB Output is correct
125 Correct 1045 ms 33760 KB Output is correct
126 Correct 1054 ms 33876 KB Output is correct
127 Correct 1055 ms 33748 KB Output is correct
128 Correct 1049 ms 33728 KB Output is correct
129 Correct 1037 ms 33744 KB Output is correct
130 Correct 1046 ms 33876 KB Output is correct
131 Correct 1029 ms 33740 KB Output is correct
132 Correct 1047 ms 33760 KB Output is correct
133 Correct 1040 ms 33868 KB Output is correct