Submission #224740

# Submission time Handle Problem Language Result Execution time Memory
224740 2020-04-18T17:20:10 Z Bruteforceman Bulldozer (JOI17_bulldozer) C++11
100 / 100
1835 ms 79448 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair <int, int>;
const int maxn = 2005;
struct point {
  long long x, y, w;
  point () {}
  point (long long x, long long y) : x(x), y(y) {}
  point operator - (point p) {
    return point(x - p.x, y - p.y);
  }
  point operator + (point p) {
    return point(x + p.x, y + p.y);
  }
  point normalize() {
    long long d = __gcd(abs(x), abs(y));
    if(d == 0) return *this;
    else return point(x / d, y / d);
  }
} a[maxn];
long long dot(point p, point q) { return p.x*q.x + p.y*q.y; }
long long cross(point p, point q) { return p.x*q.y - q.x*p.y; }
bool operator < (point p, point q) {
  return cross(p, q) > 0;
}
long long dist(point p) { return dot(p, p); }

bool vis[maxn];
int n;
int cost[maxn];
int pos[maxn], c[maxn];

struct data {
  long long sum, opt, pre, suf;
} t[maxn * 4];
struct info {
    point p;
    int i, j;
    info (point p, int i, int j) : p(p), i(i), j(j) {}
    info () {}
    bool operator < (info x) const {
        if(!cross(p, x.p)) {
            return dist(a[i] - a[j]) > dist(a[x.i] - a[x.j]);
        }
        return p < x.p; 
    }
};

data merge(data p, data q) {
  data x;
  x.sum = p.sum + q.sum;
  x.pre = max(p.pre, p.sum + q.pre);
  x.suf = max(q.suf, q.sum + p.suf);
  x.opt = max(p.opt, q.opt);
  x.opt = max(x.opt, p.suf + q.pre);
  return x;
}
void update(int x, int val, int c = 1, int b = 1, int e = n) {
  if(b == e) {
    t[c].sum = val;
    t[c].pre = t[c].suf = t[c].opt = max(0, val);
    return ;
  }
  int m = (b + e) >> 1;
  int l = c << 1;
  int r = l + 1;
  if(x <= m) update(x, val, l, b, m);
  else update(x, val, r, m + 1, e);
  t[c] = merge(t[l], t[r]);
}
long long maxSubarray() {
  return t[1].opt;
}
int main() {
  ios_base :: sync_with_stdio (false);
  cin.tie(0);

  cin >> n;
  long long ans = 0;
  for(int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y >> a[i].w;
    ans = max(ans, a[i].w);
  }
  sort(a + 1, a + n + 1, [&] (point p, point q) {
      return make_pair(p.y, p.x) < make_pair(q.y, q.x);  });

  vector <info> can;
  for(int i = 1; i <= n; i++) {
    for(int j = i + 1; j <= n; j++) {
      point p = a[j] - a[i];
      p = p.normalize();
      can.emplace_back(p, i, j);
    }
  }
  for(int i = 1; i <= n; i++) {
    pos[i] = i;
    c[i] = i;
    cost[i] = a[i].w;
    update(i, cost[i]);
  }
  sort(can.begin(), can.end());
  int now = 0;
  while(now < can.size()) {
    vector <pair <int, int>> v;
    do {
        v.emplace_back(can[now].i, can[now].j);
        ++now;
    } while (now < can.size() && cross(can[now - 1].p, can[now].p) == 0);
    vector <pii> affected;
    for(auto j : v) {
      if(vis[pos[j.first]]) continue;
      for(int k = pos[j.first]; k <= pos[j.second]; k++) {
        vis[k] = true;
      }
      affected.emplace_back(pos[j.first], pos[j.second]);
    }
    ans = max(ans, maxSubarray());
    for(auto j : affected) {
      reverse(c + j.first, c + j.second + 1);
      for(int k = j.first; k <= j.second; k++) {
        vis[k] = false;
        pos[c[k]] = k;
        cost[k] = a[c[k]].w;
        update(k, cost[k]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:103:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(now < can.size()) {
         ~~~~^~~~~~~~~~~~
bulldozer.cpp:108:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     } while (now < can.size() && cross(can[now - 1].p, can[now].p) == 0);
              ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 6 ms 768 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 384 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 8 ms 768 KB Output is correct
5 Correct 8 ms 768 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 8 ms 768 KB Output is correct
8 Correct 8 ms 768 KB Output is correct
9 Correct 8 ms 768 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 11 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 8 ms 768 KB Output is correct
27 Correct 7 ms 768 KB Output is correct
28 Correct 7 ms 768 KB Output is correct
29 Correct 7 ms 768 KB Output is correct
30 Correct 7 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 8 ms 768 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 8 ms 768 KB Output is correct
5 Correct 8 ms 768 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 8 ms 768 KB Output is correct
8 Correct 8 ms 768 KB Output is correct
9 Correct 8 ms 768 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 11 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 8 ms 768 KB Output is correct
27 Correct 7 ms 768 KB Output is correct
28 Correct 7 ms 768 KB Output is correct
29 Correct 7 ms 768 KB Output is correct
30 Correct 7 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 1763 ms 66268 KB Output is correct
34 Correct 1748 ms 66204 KB Output is correct
35 Correct 1760 ms 66332 KB Output is correct
36 Correct 1800 ms 66204 KB Output is correct
37 Correct 1750 ms 66204 KB Output is correct
38 Correct 1750 ms 66328 KB Output is correct
39 Correct 1750 ms 66204 KB Output is correct
40 Correct 1747 ms 66204 KB Output is correct
41 Correct 1757 ms 66300 KB Output is correct
42 Correct 1764 ms 66208 KB Output is correct
43 Correct 1717 ms 66204 KB Output is correct
44 Correct 1698 ms 66204 KB Output is correct
45 Correct 1691 ms 66200 KB Output is correct
46 Correct 1733 ms 66332 KB Output is correct
47 Correct 1726 ms 66208 KB Output is correct
48 Correct 1750 ms 66204 KB Output is correct
49 Correct 1700 ms 66208 KB Output is correct
50 Correct 1707 ms 66204 KB Output is correct
51 Correct 1722 ms 66204 KB Output is correct
52 Correct 1686 ms 66204 KB Output is correct
53 Correct 1707 ms 66332 KB Output is correct
54 Correct 1711 ms 66204 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 8 ms 768 KB Output is correct
5 Correct 8 ms 768 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 8 ms 768 KB Output is correct
8 Correct 8 ms 768 KB Output is correct
9 Correct 8 ms 768 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 11 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 8 ms 768 KB Output is correct
27 Correct 7 ms 768 KB Output is correct
28 Correct 7 ms 768 KB Output is correct
29 Correct 7 ms 768 KB Output is correct
30 Correct 7 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 1763 ms 66268 KB Output is correct
34 Correct 1748 ms 66204 KB Output is correct
35 Correct 1760 ms 66332 KB Output is correct
36 Correct 1800 ms 66204 KB Output is correct
37 Correct 1750 ms 66204 KB Output is correct
38 Correct 1750 ms 66328 KB Output is correct
39 Correct 1750 ms 66204 KB Output is correct
40 Correct 1747 ms 66204 KB Output is correct
41 Correct 1757 ms 66300 KB Output is correct
42 Correct 1764 ms 66208 KB Output is correct
43 Correct 1717 ms 66204 KB Output is correct
44 Correct 1698 ms 66204 KB Output is correct
45 Correct 1691 ms 66200 KB Output is correct
46 Correct 1733 ms 66332 KB Output is correct
47 Correct 1726 ms 66208 KB Output is correct
48 Correct 1750 ms 66204 KB Output is correct
49 Correct 1700 ms 66208 KB Output is correct
50 Correct 1707 ms 66204 KB Output is correct
51 Correct 1722 ms 66204 KB Output is correct
52 Correct 1686 ms 66204 KB Output is correct
53 Correct 1707 ms 66332 KB Output is correct
54 Correct 1711 ms 66204 KB Output is correct
55 Correct 1759 ms 66340 KB Output is correct
56 Correct 1728 ms 66204 KB Output is correct
57 Correct 1747 ms 66352 KB Output is correct
58 Correct 1747 ms 66388 KB Output is correct
59 Correct 1756 ms 66208 KB Output is correct
60 Correct 1755 ms 66204 KB Output is correct
61 Correct 1744 ms 66464 KB Output is correct
62 Correct 1766 ms 66204 KB Output is correct
63 Correct 1740 ms 66356 KB Output is correct
64 Correct 1742 ms 66200 KB Output is correct
65 Correct 1774 ms 66204 KB Output is correct
66 Correct 1747 ms 66204 KB Output is correct
67 Correct 1756 ms 66204 KB Output is correct
68 Correct 1754 ms 66200 KB Output is correct
69 Correct 1754 ms 66204 KB Output is correct
70 Correct 1756 ms 66204 KB Output is correct
71 Correct 1745 ms 66312 KB Output is correct
72 Correct 1734 ms 66204 KB Output is correct
73 Correct 1756 ms 66204 KB Output is correct
74 Correct 1747 ms 66204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 6 ms 768 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 7 ms 768 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 7 ms 768 KB Output is correct
19 Correct 8 ms 768 KB Output is correct
20 Correct 8 ms 768 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 8 ms 768 KB Output is correct
23 Correct 8 ms 768 KB Output is correct
24 Correct 8 ms 768 KB Output is correct
25 Correct 7 ms 768 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 11 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 8 ms 768 KB Output is correct
42 Correct 7 ms 768 KB Output is correct
43 Correct 7 ms 768 KB Output is correct
44 Correct 7 ms 768 KB Output is correct
45 Correct 7 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 1763 ms 66268 KB Output is correct
49 Correct 1748 ms 66204 KB Output is correct
50 Correct 1760 ms 66332 KB Output is correct
51 Correct 1800 ms 66204 KB Output is correct
52 Correct 1750 ms 66204 KB Output is correct
53 Correct 1750 ms 66328 KB Output is correct
54 Correct 1750 ms 66204 KB Output is correct
55 Correct 1747 ms 66204 KB Output is correct
56 Correct 1757 ms 66300 KB Output is correct
57 Correct 1764 ms 66208 KB Output is correct
58 Correct 1717 ms 66204 KB Output is correct
59 Correct 1698 ms 66204 KB Output is correct
60 Correct 1691 ms 66200 KB Output is correct
61 Correct 1733 ms 66332 KB Output is correct
62 Correct 1726 ms 66208 KB Output is correct
63 Correct 1750 ms 66204 KB Output is correct
64 Correct 1700 ms 66208 KB Output is correct
65 Correct 1707 ms 66204 KB Output is correct
66 Correct 1722 ms 66204 KB Output is correct
67 Correct 1686 ms 66204 KB Output is correct
68 Correct 1707 ms 66332 KB Output is correct
69 Correct 1711 ms 66204 KB Output is correct
70 Correct 1759 ms 66340 KB Output is correct
71 Correct 1728 ms 66204 KB Output is correct
72 Correct 1747 ms 66352 KB Output is correct
73 Correct 1747 ms 66388 KB Output is correct
74 Correct 1756 ms 66208 KB Output is correct
75 Correct 1755 ms 66204 KB Output is correct
76 Correct 1744 ms 66464 KB Output is correct
77 Correct 1766 ms 66204 KB Output is correct
78 Correct 1740 ms 66356 KB Output is correct
79 Correct 1742 ms 66200 KB Output is correct
80 Correct 1774 ms 66204 KB Output is correct
81 Correct 1747 ms 66204 KB Output is correct
82 Correct 1756 ms 66204 KB Output is correct
83 Correct 1754 ms 66200 KB Output is correct
84 Correct 1754 ms 66204 KB Output is correct
85 Correct 1756 ms 66204 KB Output is correct
86 Correct 1745 ms 66312 KB Output is correct
87 Correct 1734 ms 66204 KB Output is correct
88 Correct 1756 ms 66204 KB Output is correct
89 Correct 1747 ms 66204 KB Output is correct
90 Correct 1826 ms 66208 KB Output is correct
91 Correct 1740 ms 66204 KB Output is correct
92 Correct 1757 ms 66352 KB Output is correct
93 Correct 1835 ms 66204 KB Output is correct
94 Correct 1739 ms 66248 KB Output is correct
95 Correct 1763 ms 66248 KB Output is correct
96 Correct 1780 ms 66332 KB Output is correct
97 Correct 1760 ms 66332 KB Output is correct
98 Correct 1764 ms 66328 KB Output is correct
99 Correct 1745 ms 66204 KB Output is correct
100 Correct 1043 ms 79192 KB Output is correct
101 Correct 1066 ms 79448 KB Output is correct
102 Correct 1062 ms 79248 KB Output is correct
103 Correct 1047 ms 79448 KB Output is correct
104 Correct 1048 ms 79388 KB Output is correct
105 Correct 1260 ms 76684 KB Output is correct
106 Correct 1234 ms 76684 KB Output is correct
107 Correct 1271 ms 76608 KB Output is correct
108 Correct 1270 ms 76688 KB Output is correct
109 Correct 1267 ms 76572 KB Output is correct
110 Correct 1220 ms 66208 KB Output is correct
111 Correct 1207 ms 66204 KB Output is correct
112 Correct 1204 ms 66208 KB Output is correct
113 Correct 1227 ms 66332 KB Output is correct
114 Correct 1223 ms 66204 KB Output is correct
115 Correct 1226 ms 66208 KB Output is correct
116 Correct 1214 ms 66208 KB Output is correct
117 Correct 1211 ms 66204 KB Output is correct
118 Correct 1201 ms 66204 KB Output is correct
119 Correct 1213 ms 66204 KB Output is correct
120 Correct 5 ms 384 KB Output is correct
121 Correct 5 ms 384 KB Output is correct
122 Correct 1663 ms 66284 KB Output is correct
123 Correct 1694 ms 66240 KB Output is correct
124 Correct 1659 ms 66204 KB Output is correct
125 Correct 1666 ms 66204 KB Output is correct
126 Correct 1660 ms 66336 KB Output is correct
127 Correct 1653 ms 66208 KB Output is correct
128 Correct 1675 ms 66204 KB Output is correct
129 Correct 1684 ms 66208 KB Output is correct
130 Correct 1637 ms 66280 KB Output is correct
131 Correct 1645 ms 66204 KB Output is correct
132 Correct 1651 ms 66336 KB Output is correct
133 Correct 1640 ms 66336 KB Output is correct