답안 #229363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229363 2020-05-04T10:11:32 Z fedoseevtimofey Bulldozer (JOI17_bulldozer) C++14
20 / 100
2000 ms 66588 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 &b) const {
    const point &a = *this;
    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 = 2500;
Node t[4 * N];

void modify(int id, ll val, int l, int r, int v) {
  if (l == r) {
    t[v] = Node(val);
  } else {
    int m = (l + r) >> 1;
    if (id <= m) modify(id, val, l, m, 2 * v + 1);
    else modify(id, val, m + 1, r, 2 * v + 2);
    t[v] = t[2 * v + 1] + t[2 * v + 2];
  }
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  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 <pair <point, pair <int, int>>> dir;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j) continue;
      dir.emplace_back(a[i] - a[j], make_pair(i, j));
    }
  }
  sort(dir.begin(), dir.end());
  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;
  for (int i = 0; i < n; ++i) {
    modify(pos[i], w[i], 0, n - 1, 0);
  }
  ll ans = t[0].best;
  for (auto d : dir) {
    int i = d.second.first, j = d.second.second;
    modify(pos[i], w[j], 0, n - 1, 0);
    modify(pos[j], w[i], 0, n - 1, 0);
    swap(pos[i], pos[j]);
    ans = max(ans, t[0].best);
  }

  cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 1024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1024 KB Output is correct
2 Correct 9 ms 1024 KB Output is correct
3 Correct 9 ms 1024 KB Output is correct
4 Correct 9 ms 1024 KB Output is correct
5 Correct 9 ms 1024 KB Output is correct
6 Correct 9 ms 1024 KB Output is correct
7 Correct 9 ms 1024 KB Output is correct
8 Correct 8 ms 1024 KB Output is correct
9 Correct 9 ms 1024 KB Output is correct
10 Correct 9 ms 1024 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 640 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 9 ms 1152 KB Output is correct
22 Correct 9 ms 1024 KB Output is correct
23 Correct 8 ms 1024 KB Output is correct
24 Correct 9 ms 1024 KB Output is correct
25 Correct 9 ms 1024 KB Output is correct
26 Correct 8 ms 1024 KB Output is correct
27 Correct 9 ms 1024 KB Output is correct
28 Correct 9 ms 1024 KB Output is correct
29 Correct 9 ms 1024 KB Output is correct
30 Correct 8 ms 1024 KB Output is correct
31 Correct 9 ms 1024 KB Output is correct
32 Correct 9 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1024 KB Output is correct
2 Correct 9 ms 1024 KB Output is correct
3 Correct 9 ms 1024 KB Output is correct
4 Correct 9 ms 1024 KB Output is correct
5 Correct 9 ms 1024 KB Output is correct
6 Correct 9 ms 1024 KB Output is correct
7 Correct 9 ms 1024 KB Output is correct
8 Correct 8 ms 1024 KB Output is correct
9 Correct 9 ms 1024 KB Output is correct
10 Correct 9 ms 1024 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 640 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 9 ms 1152 KB Output is correct
22 Correct 9 ms 1024 KB Output is correct
23 Correct 8 ms 1024 KB Output is correct
24 Correct 9 ms 1024 KB Output is correct
25 Correct 9 ms 1024 KB Output is correct
26 Correct 8 ms 1024 KB Output is correct
27 Correct 9 ms 1024 KB Output is correct
28 Correct 9 ms 1024 KB Output is correct
29 Correct 9 ms 1024 KB Output is correct
30 Correct 8 ms 1024 KB Output is correct
31 Correct 9 ms 1024 KB Output is correct
32 Correct 9 ms 1024 KB Output is correct
33 Execution timed out 2085 ms 66588 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1024 KB Output is correct
2 Correct 9 ms 1024 KB Output is correct
3 Correct 9 ms 1024 KB Output is correct
4 Correct 9 ms 1024 KB Output is correct
5 Correct 9 ms 1024 KB Output is correct
6 Correct 9 ms 1024 KB Output is correct
7 Correct 9 ms 1024 KB Output is correct
8 Correct 8 ms 1024 KB Output is correct
9 Correct 9 ms 1024 KB Output is correct
10 Correct 9 ms 1024 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 640 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 9 ms 1152 KB Output is correct
22 Correct 9 ms 1024 KB Output is correct
23 Correct 8 ms 1024 KB Output is correct
24 Correct 9 ms 1024 KB Output is correct
25 Correct 9 ms 1024 KB Output is correct
26 Correct 8 ms 1024 KB Output is correct
27 Correct 9 ms 1024 KB Output is correct
28 Correct 9 ms 1024 KB Output is correct
29 Correct 9 ms 1024 KB Output is correct
30 Correct 8 ms 1024 KB Output is correct
31 Correct 9 ms 1024 KB Output is correct
32 Correct 9 ms 1024 KB Output is correct
33 Execution timed out 2085 ms 66588 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 1024 KB Output isn't correct
2 Halted 0 ms 0 KB -