Submission #37697

# Submission time Handle Problem Language Result Execution time Memory
37697 2017-12-27T02:45:49 Z funcsr Bulldozer (JOI17_bulldozer) C++14
0 / 100
91 ms 94748 KB
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
typedef pair<P, int> P2;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
struct Node {
  long long s, l, r, m;
  Node(long long s, long long l, long long r, long long m) : s(s), l(l), r(r), m(m) {}
  Node(long long w) : Node(w, max(w, 0LL), max(w, 0LL), max(w, 0LL)) {}
  Node() : Node(0) {}
};
Node op(const Node &a, const Node &b) {
  return Node(
    a.s + b.s,
    max(a.l, a.s + b.l),
    max(b.r, b.s + a.r),
    max(max(a.m, b.m), a.r + b.l)
  );
}

#define MAX_N (1<<11)
Node seg[MAX_N*2-1];
void update(int k, Node x) {
  k += MAX_N-1;
  seg[k] = x;
  while (k > 0) {
    k = (k-1)/2;
    seg[k] = op(seg[k*2+1], seg[k*2+2]);
  }
}

int N;
int X[2000], Y[2000], W[2000];

struct Rel {
  int p, q;
  Rel(int p, int q) : p(p), q(q) {
    if (q < 0) p = -p, q = -q;
  }
  bool operator<(const Rel& b) const { return 1LL*p*b.q < 1LL*b.p*q; }
  bool operator==(const Rel& b) const { return 1LL*p*b.q == 1LL*b.p*q; }
};
int pos[2000], rev[2000];
vector<int> G[1999000];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  vector<P2> ps;
  rep(i, N) {
    int x, y, w;
    cin >> x >> y >> w;
    ps.pb(P2(P(x, -y), w));
  }
  sort(all(ps));
  rep(i, N) {
    X[i] = ps[i]._1._1, Y[i] = -ps[i]._1._2, W[i] = ps[i]._2;
    pos[i] = i, rev[i] = i;
    update(i, Node(W[i]));
  }

  vector<pair<Rel, P>> lines;
  rep(i, N) rep(j, i) {
    Rel r = Rel(-1, 0);
    if (X[i] != X[j]) r = Rel(Y[i]-Y[j], X[i]-X[j]);
    lines.pb(make_pair(r, P(i, j)));
  }
  sort(all(lines));
  long long m = seg[0].m;
  vector<long long> bs;
  Rel a = lines[0]._1;
  vector<int> ln;
  rep(e, lines.size()) {
    if (!(a == lines[e]._1)) a = lines[e]._1;
    P p = lines[e]._2;
    bs.pb(1LL*Y[p._1]*a.q-1LL*X[p._1]*a.p);
    ln.pb(p._1);
    ln.pb(p._2);

    if (e+1 >= lines.size() || !(a == lines[e+1]._1)) {
      sort(all(bs)); uniq(bs);
      for (int p : ln) {
        int k = index(bs, 1LL*Y[p]*a.q-1LL*X[p]*a.p);
        G[k].pb(pos[p]);
      }
      rep(i, bs.size()) {
        vector<int> &ps = G[i];
        sort(all(ps)); uniq(ps);
        rep(i, ps.size()/2) {
          int a = rev[ps[i]], b = rev[ps[(int)ps.size()-1-i]];
          swap(pos[a], pos[b]);
          rev[pos[a]] = a;
          rev[pos[b]] = b;
          update(pos[a], Node(W[a]));
          update(pos[b], Node(W[b]));
        }
      }
      rep(i, bs.size()) G[i].clear();
      bs.clear();
      ln.clear();
      m = max(m, seg[0].m);
    }
  }
  cout << m << "\n";
  return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i, n) for (int i=0; i<(n); i++)
                                  ^
bulldozer.cpp:94:3: note: in expansion of macro 'rep'
   rep(e, lines.size()) {
   ^~~
bulldozer.cpp:101:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (e+1 >= lines.size() || !(a == lines[e+1]._1)) {
         ~~~~^~~~~~~~~~~~~~~
bulldozer.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i, n) for (int i=0; i<(n); i++)
                                  ^
bulldozer.cpp:107:7: note: in expansion of macro 'rep'
       rep(i, bs.size()) {
       ^~~
bulldozer.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i, n) for (int i=0; i<(n); i++)
                                  ^
bulldozer.cpp:110:9: note: in expansion of macro 'rep'
         rep(i, ps.size()/2) {
         ^~~
bulldozer.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i, n) for (int i=0; i<(n); i++)
                                  ^
bulldozer.cpp:119:7: note: in expansion of macro 'rep'
       rep(i, bs.size()) G[i].clear();
       ^~~
# Verdict Execution time Memory Grader output
1 Correct 51 ms 47736 KB Output is correct
2 Correct 43 ms 47676 KB Output is correct
3 Correct 43 ms 47644 KB Output is correct
4 Correct 44 ms 47744 KB Output is correct
5 Correct 43 ms 47736 KB Output is correct
6 Correct 46 ms 47760 KB Output is correct
7 Correct 44 ms 47640 KB Output is correct
8 Correct 45 ms 47708 KB Output is correct
9 Correct 42 ms 47888 KB Output is correct
10 Correct 43 ms 47736 KB Output is correct
11 Runtime error 91 ms 94748 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 47684 KB Output is correct
2 Correct 44 ms 47648 KB Output is correct
3 Correct 45 ms 47608 KB Output is correct
4 Correct 44 ms 47608 KB Output is correct
5 Correct 42 ms 47648 KB Output is correct
6 Correct 44 ms 47640 KB Output is correct
7 Correct 44 ms 47608 KB Output is correct
8 Correct 44 ms 47608 KB Output is correct
9 Correct 44 ms 47608 KB Output is correct
10 Correct 44 ms 47608 KB Output is correct
11 Runtime error 88 ms 94636 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 47684 KB Output is correct
2 Correct 44 ms 47648 KB Output is correct
3 Correct 45 ms 47608 KB Output is correct
4 Correct 44 ms 47608 KB Output is correct
5 Correct 42 ms 47648 KB Output is correct
6 Correct 44 ms 47640 KB Output is correct
7 Correct 44 ms 47608 KB Output is correct
8 Correct 44 ms 47608 KB Output is correct
9 Correct 44 ms 47608 KB Output is correct
10 Correct 44 ms 47608 KB Output is correct
11 Runtime error 88 ms 94636 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 47684 KB Output is correct
2 Correct 44 ms 47648 KB Output is correct
3 Correct 45 ms 47608 KB Output is correct
4 Correct 44 ms 47608 KB Output is correct
5 Correct 42 ms 47648 KB Output is correct
6 Correct 44 ms 47640 KB Output is correct
7 Correct 44 ms 47608 KB Output is correct
8 Correct 44 ms 47608 KB Output is correct
9 Correct 44 ms 47608 KB Output is correct
10 Correct 44 ms 47608 KB Output is correct
11 Runtime error 88 ms 94636 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 47736 KB Output is correct
2 Correct 43 ms 47676 KB Output is correct
3 Correct 43 ms 47644 KB Output is correct
4 Correct 44 ms 47744 KB Output is correct
5 Correct 43 ms 47736 KB Output is correct
6 Correct 46 ms 47760 KB Output is correct
7 Correct 44 ms 47640 KB Output is correct
8 Correct 45 ms 47708 KB Output is correct
9 Correct 42 ms 47888 KB Output is correct
10 Correct 43 ms 47736 KB Output is correct
11 Runtime error 91 ms 94748 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -