Submission #498500

# Submission time Handle Problem Language Result Execution time Memory
498500 2021-12-25T10:47:42 Z 600Mihnea Bulldozer (JOI17_bulldozer) C++17
25 / 100
2000 ms 165184 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Point {
  ll x;
  ll y;
  ll value;
};

struct R {
  int sgn;
  ll up;
  ll down;
  int i;
  int j;
};

R get(ll x, ll y) {
  R sol;
  ll g = __gcd(x, y);
  x /= g;
  y /= g;

  sol.sgn = +1;
  if (x < 0 && y < 0) {
    x *= -1;
    y *= -1;
  }
  if (x < 0 || y < 0) {
    sol.sgn = -1;
  }
  sol.up = abs(x);
  sol.down = abs(y);
  return sol;
}

bool operator < (R a, R b) {
  if (a.sgn != b.sgn) {
    return a.sgn < b.sgn;
  }
  if (a.sgn == -1) {
    swap(a, b);
  }
  return a.up * b.down < b.up * a.down;
}

bool initialCmp(Point a, Point b) {
  if (a.y == b.y) {
    return a.x < b.x;
  }
  return a.y < b.y;
}

const int N = 2000 + 7;
int n;
R panta[N][N];
Point points[N];

void sneakyHack() {

  for (int i = 1; i <= n; i++) {
    swap(points[i].x, points[i].y);
  }
}

int ord[N];
int inv[N];

int main() {
  bool isHome;

  isHome = true;
  isHome = false;

  if (isHome) {
    freopen ("input", "r", stdin);
  } else {
    ios::sync_with_stdio(0); cin.tie(0);
  }

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> points[i].x >> points[i].y >> points[i].value;
  }

  ll best = 0;

  for (int iteration = 1; iteration <= 2; iteration++) {
    sneakyHack();
    sort(points + 1, points + n + 1, initialCmp);

    for (int i = 1; i <= n; i++) {
      ord[i] = i;
      inv[i] = i;
      for (int j = i + 1; j <= n; j++) {
        panta[i][j] = get(points[i].x - points[j].x, points[i].y - points[j].y);
        panta[i][j].i = i;
        panta[i][j].j = j;
      }
    }
    vector<R> all;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        all.push_back(panta[i][j]);
      }
    }
    stable_sort(all.begin(), all.end());
    ll current = 0;
    for (int i = 1; i <= n; i++) {
      current = max(0LL, current + points[ord[i]].value);
      best = max(best, current);
    }

    /// all[it] < all[it + 1]
    int l = 0;
    while (l < (int) all.size()) {
      int r = l;
      while (r + 1 < (int) all.size() && !(all[r] < all[r + 1])) {
        r++;
      }

      for (int it = l; it <= r; it++) {
        int i = all[it].i;
        int j = all[it].j;
        int pos_i = inv[i];
        int pos_j = inv[j];

        swap(ord[pos_i], ord[pos_j]);
        inv[ord[pos_i]] = pos_i;
        inv[ord[pos_j]] = pos_j;
      }

      ll current = 0;
      for (int i = 1; i <= n; i++) {
        current = max(0LL, current + points[ord[i]].value);
        best = max(best, current);
      }

      l = r + 1;
    }



  }

  cout << best << "\n";




  return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:79:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |     freopen ("input", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1252 KB Output is correct
2 Correct 1 ms 1252 KB Output is correct
3 Correct 1 ms 1252 KB Output is correct
4 Correct 1 ms 1252 KB Output is correct
5 Correct 1 ms 1252 KB Output is correct
6 Correct 2 ms 1252 KB Output is correct
7 Correct 2 ms 1252 KB Output is correct
8 Correct 1 ms 1252 KB Output is correct
9 Correct 1 ms 1252 KB Output is correct
10 Correct 1 ms 1252 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 332 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 0 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1252 KB Output is correct
2 Correct 5 ms 1252 KB Output is correct
3 Correct 5 ms 1252 KB Output is correct
4 Correct 5 ms 1252 KB Output is correct
5 Correct 4 ms 1304 KB Output is correct
6 Correct 5 ms 1252 KB Output is correct
7 Correct 4 ms 1252 KB Output is correct
8 Correct 4 ms 1252 KB Output is correct
9 Correct 4 ms 1252 KB Output is correct
10 Correct 5 ms 1252 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 4 ms 1252 KB Output is correct
22 Correct 4 ms 1252 KB Output is correct
23 Correct 4 ms 1252 KB Output is correct
24 Correct 4 ms 1252 KB Output is correct
25 Correct 4 ms 1252 KB Output is correct
26 Correct 4 ms 1244 KB Output is correct
27 Correct 4 ms 1252 KB Output is correct
28 Correct 4 ms 1252 KB Output is correct
29 Correct 4 ms 1252 KB Output is correct
30 Correct 4 ms 1240 KB Output is correct
31 Correct 4 ms 1252 KB Output is correct
32 Correct 4 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1252 KB Output is correct
2 Correct 5 ms 1252 KB Output is correct
3 Correct 5 ms 1252 KB Output is correct
4 Correct 5 ms 1252 KB Output is correct
5 Correct 4 ms 1304 KB Output is correct
6 Correct 5 ms 1252 KB Output is correct
7 Correct 4 ms 1252 KB Output is correct
8 Correct 4 ms 1252 KB Output is correct
9 Correct 4 ms 1252 KB Output is correct
10 Correct 5 ms 1252 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 4 ms 1252 KB Output is correct
22 Correct 4 ms 1252 KB Output is correct
23 Correct 4 ms 1252 KB Output is correct
24 Correct 4 ms 1252 KB Output is correct
25 Correct 4 ms 1252 KB Output is correct
26 Correct 4 ms 1244 KB Output is correct
27 Correct 4 ms 1252 KB Output is correct
28 Correct 4 ms 1252 KB Output is correct
29 Correct 4 ms 1252 KB Output is correct
30 Correct 4 ms 1240 KB Output is correct
31 Correct 4 ms 1252 KB Output is correct
32 Correct 4 ms 1236 KB Output is correct
33 Execution timed out 2071 ms 165184 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1252 KB Output is correct
2 Correct 5 ms 1252 KB Output is correct
3 Correct 5 ms 1252 KB Output is correct
4 Correct 5 ms 1252 KB Output is correct
5 Correct 4 ms 1304 KB Output is correct
6 Correct 5 ms 1252 KB Output is correct
7 Correct 4 ms 1252 KB Output is correct
8 Correct 4 ms 1252 KB Output is correct
9 Correct 4 ms 1252 KB Output is correct
10 Correct 5 ms 1252 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 4 ms 1252 KB Output is correct
22 Correct 4 ms 1252 KB Output is correct
23 Correct 4 ms 1252 KB Output is correct
24 Correct 4 ms 1252 KB Output is correct
25 Correct 4 ms 1252 KB Output is correct
26 Correct 4 ms 1244 KB Output is correct
27 Correct 4 ms 1252 KB Output is correct
28 Correct 4 ms 1252 KB Output is correct
29 Correct 4 ms 1252 KB Output is correct
30 Correct 4 ms 1240 KB Output is correct
31 Correct 4 ms 1252 KB Output is correct
32 Correct 4 ms 1236 KB Output is correct
33 Execution timed out 2071 ms 165184 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1252 KB Output is correct
2 Correct 1 ms 1252 KB Output is correct
3 Correct 1 ms 1252 KB Output is correct
4 Correct 1 ms 1252 KB Output is correct
5 Correct 1 ms 1252 KB Output is correct
6 Correct 2 ms 1252 KB Output is correct
7 Correct 2 ms 1252 KB Output is correct
8 Correct 1 ms 1252 KB Output is correct
9 Correct 1 ms 1252 KB Output is correct
10 Correct 1 ms 1252 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 332 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 0 ms 316 KB Output is correct
16 Correct 4 ms 1252 KB Output is correct
17 Correct 5 ms 1252 KB Output is correct
18 Correct 5 ms 1252 KB Output is correct
19 Correct 5 ms 1252 KB Output is correct
20 Correct 4 ms 1304 KB Output is correct
21 Correct 5 ms 1252 KB Output is correct
22 Correct 4 ms 1252 KB Output is correct
23 Correct 4 ms 1252 KB Output is correct
24 Correct 4 ms 1252 KB Output is correct
25 Correct 5 ms 1252 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 4 ms 1252 KB Output is correct
37 Correct 4 ms 1252 KB Output is correct
38 Correct 4 ms 1252 KB Output is correct
39 Correct 4 ms 1252 KB Output is correct
40 Correct 4 ms 1252 KB Output is correct
41 Correct 4 ms 1244 KB Output is correct
42 Correct 4 ms 1252 KB Output is correct
43 Correct 4 ms 1252 KB Output is correct
44 Correct 4 ms 1252 KB Output is correct
45 Correct 4 ms 1240 KB Output is correct
46 Correct 4 ms 1252 KB Output is correct
47 Correct 4 ms 1236 KB Output is correct
48 Execution timed out 2071 ms 165184 KB Time limit exceeded
49 Halted 0 ms 0 KB -