Submission #224688

# Submission time Handle Problem Language Result Execution time Memory
224688 2020-04-18T15:27:43 Z Bruteforceman Bulldozer (JOI17_bulldozer) C++11
0 / 100
9 ms 1024 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];
long long maxSubarray() {
  long long opt = 0;
  long long ans = 0;
  long long sum = 0;
  for(int i = 1; i <= n; i++) {
    sum += cost[i];
    ans = max(ans, sum - opt);
    opt = min(opt, sum);
  }
  return ans;
}

int main() {
  cin >> n;
  for(int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y >> a[i].w;
  }
  auto cmp = [&] (point p, point q, point r) {
    return make_pair(cross(p, q), dot(p, q)) < 
      make_pair(cross(p, r), dot(p, r));
  };
  sort(a + 1, a + n + 1, [&] (point p, point q) {
      return cmp(point(1, 0), p, q); });

  map <point, vector <pair <int, int>>> 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[p].emplace_back(i, j);
    }
  }
  for(int i = 1; i <= n; i++) {
    pos[i] = i;
    c[i] = i;
    cost[i] = a[i].w;
  }
  long long ans = 0;
  for(auto i : can) {
    vector <pair <int, int>> v = i.second;
    sort(v.begin(), v.end(), [&] (pii p, pii q) {
        return dist(a[p.second] - a[p.first]) > 
        dist(a[q.second] - a[q.first]); } );

    vector <pii> affected;
    for(auto j : v) {
      if(vis[j.first]) continue;
      long long total = 0;
      for(int k = pos[j.first]; k <= pos[j.second]; k++) {
        vis[k] = true;
        total += cost[k];
        cost[k] = 0;
      }
      cost[pos[j.first]] = total;
      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;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1024 KB Output is correct
2 Correct 8 ms 1024 KB Output is correct
3 Correct 8 ms 896 KB Output is correct
4 Correct 9 ms 1024 KB Output is correct
5 Correct 8 ms 896 KB Output is correct
6 Correct 9 ms 1024 KB Output is correct
7 Correct 8 ms 1024 KB Output is correct
8 Correct 8 ms 896 KB Output is correct
9 Correct 9 ms 1024 KB Output is correct
10 Correct 8 ms 1024 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Incorrect 5 ms 384 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1024 KB Output is correct
2 Correct 8 ms 1024 KB Output is correct
3 Correct 8 ms 896 KB Output is correct
4 Correct 9 ms 1024 KB Output is correct
5 Correct 8 ms 896 KB Output is correct
6 Correct 9 ms 1024 KB Output is correct
7 Correct 8 ms 1024 KB Output is correct
8 Correct 8 ms 896 KB Output is correct
9 Correct 9 ms 1024 KB Output is correct
10 Correct 8 ms 1024 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Incorrect 5 ms 384 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1024 KB Output is correct
2 Correct 8 ms 1024 KB Output is correct
3 Correct 8 ms 896 KB Output is correct
4 Correct 9 ms 1024 KB Output is correct
5 Correct 8 ms 896 KB Output is correct
6 Correct 9 ms 1024 KB Output is correct
7 Correct 8 ms 1024 KB Output is correct
8 Correct 8 ms 896 KB Output is correct
9 Correct 9 ms 1024 KB Output is correct
10 Correct 8 ms 1024 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Incorrect 5 ms 384 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -