답안 #37699

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
37699 2017-12-27T02:52:02 Z funcsr Bulldozer (JOI17_bulldozer) C++14
100 / 100
978 ms 100352 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]));
  }
  if (N == 1) {
    cout << max(W[0], 0) << "\n";
    return 0;
  }

  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(pos[p._1]);
    ln.pb(pos[p._2]);

    if (e+1 >= lines.size() || !(a == lines[e+1]._1)) {
      sort(all(bs)); uniq(bs);
      sort(all(ln)); uniq(ln);
      for (int p : ln) {
        int k = index(bs, 1LL*Y[rev[p]]*a.q-1LL*X[rev[p]]*a.p);
        G[k].pb(p);
      }
      rep(i, bs.size()) {
        vector<int> &ps = G[i];
        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:98:3: note: in expansion of macro 'rep'
   rep(e, lines.size()) {
   ^~~
bulldozer.cpp:105: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:112: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:114: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:123:7: note: in expansion of macro 'rep'
       rep(i, bs.size()) G[i].clear();
       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 47608 KB Output is correct
2 Correct 42 ms 47708 KB Output is correct
3 Correct 43 ms 47624 KB Output is correct
4 Correct 45 ms 47608 KB Output is correct
5 Correct 44 ms 47736 KB Output is correct
6 Correct 47 ms 47708 KB Output is correct
7 Correct 45 ms 47712 KB Output is correct
8 Correct 44 ms 47720 KB Output is correct
9 Correct 47 ms 47708 KB Output is correct
10 Correct 44 ms 47608 KB Output is correct
11 Correct 48 ms 47452 KB Output is correct
12 Correct 44 ms 47352 KB Output is correct
13 Correct 43 ms 47464 KB Output is correct
14 Correct 44 ms 47352 KB Output is correct
15 Correct 43 ms 47352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 47612 KB Output is correct
2 Correct 44 ms 47616 KB Output is correct
3 Correct 44 ms 47608 KB Output is correct
4 Correct 46 ms 47608 KB Output is correct
5 Correct 47 ms 47608 KB Output is correct
6 Correct 46 ms 47608 KB Output is correct
7 Correct 46 ms 47612 KB Output is correct
8 Correct 45 ms 47608 KB Output is correct
9 Correct 45 ms 47580 KB Output is correct
10 Correct 45 ms 47744 KB Output is correct
11 Correct 46 ms 47360 KB Output is correct
12 Correct 42 ms 47352 KB Output is correct
13 Correct 41 ms 47416 KB Output is correct
14 Correct 42 ms 47480 KB Output is correct
15 Correct 43 ms 47468 KB Output is correct
16 Correct 41 ms 47452 KB Output is correct
17 Correct 45 ms 47460 KB Output is correct
18 Correct 41 ms 47468 KB Output is correct
19 Correct 43 ms 47340 KB Output is correct
20 Correct 42 ms 47360 KB Output is correct
21 Correct 44 ms 47612 KB Output is correct
22 Correct 45 ms 47680 KB Output is correct
23 Correct 43 ms 47648 KB Output is correct
24 Correct 44 ms 47568 KB Output is correct
25 Correct 43 ms 47612 KB Output is correct
26 Correct 43 ms 47612 KB Output is correct
27 Correct 43 ms 47608 KB Output is correct
28 Correct 43 ms 47736 KB Output is correct
29 Correct 43 ms 47608 KB Output is correct
30 Correct 42 ms 47608 KB Output is correct
31 Correct 44 ms 47608 KB Output is correct
32 Correct 45 ms 47608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 47612 KB Output is correct
2 Correct 44 ms 47616 KB Output is correct
3 Correct 44 ms 47608 KB Output is correct
4 Correct 46 ms 47608 KB Output is correct
5 Correct 47 ms 47608 KB Output is correct
6 Correct 46 ms 47608 KB Output is correct
7 Correct 46 ms 47612 KB Output is correct
8 Correct 45 ms 47608 KB Output is correct
9 Correct 45 ms 47580 KB Output is correct
10 Correct 45 ms 47744 KB Output is correct
11 Correct 46 ms 47360 KB Output is correct
12 Correct 42 ms 47352 KB Output is correct
13 Correct 41 ms 47416 KB Output is correct
14 Correct 42 ms 47480 KB Output is correct
15 Correct 43 ms 47468 KB Output is correct
16 Correct 41 ms 47452 KB Output is correct
17 Correct 45 ms 47460 KB Output is correct
18 Correct 41 ms 47468 KB Output is correct
19 Correct 43 ms 47340 KB Output is correct
20 Correct 42 ms 47360 KB Output is correct
21 Correct 44 ms 47612 KB Output is correct
22 Correct 45 ms 47680 KB Output is correct
23 Correct 43 ms 47648 KB Output is correct
24 Correct 44 ms 47568 KB Output is correct
25 Correct 43 ms 47612 KB Output is correct
26 Correct 43 ms 47612 KB Output is correct
27 Correct 43 ms 47608 KB Output is correct
28 Correct 43 ms 47736 KB Output is correct
29 Correct 43 ms 47608 KB Output is correct
30 Correct 42 ms 47608 KB Output is correct
31 Correct 44 ms 47608 KB Output is correct
32 Correct 45 ms 47608 KB Output is correct
33 Correct 916 ms 80468 KB Output is correct
34 Correct 921 ms 80524 KB Output is correct
35 Correct 914 ms 80464 KB Output is correct
36 Correct 937 ms 80504 KB Output is correct
37 Correct 903 ms 80464 KB Output is correct
38 Correct 904 ms 80464 KB Output is correct
39 Correct 925 ms 80480 KB Output is correct
40 Correct 917 ms 80592 KB Output is correct
41 Correct 910 ms 80484 KB Output is correct
42 Correct 903 ms 80608 KB Output is correct
43 Correct 928 ms 80480 KB Output is correct
44 Correct 954 ms 80480 KB Output is correct
45 Correct 932 ms 80492 KB Output is correct
46 Correct 945 ms 80476 KB Output is correct
47 Correct 932 ms 80464 KB Output is correct
48 Correct 942 ms 80484 KB Output is correct
49 Correct 946 ms 80480 KB Output is correct
50 Correct 934 ms 80480 KB Output is correct
51 Correct 942 ms 80464 KB Output is correct
52 Correct 927 ms 80496 KB Output is correct
53 Correct 922 ms 80484 KB Output is correct
54 Correct 938 ms 80652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 47612 KB Output is correct
2 Correct 44 ms 47616 KB Output is correct
3 Correct 44 ms 47608 KB Output is correct
4 Correct 46 ms 47608 KB Output is correct
5 Correct 47 ms 47608 KB Output is correct
6 Correct 46 ms 47608 KB Output is correct
7 Correct 46 ms 47612 KB Output is correct
8 Correct 45 ms 47608 KB Output is correct
9 Correct 45 ms 47580 KB Output is correct
10 Correct 45 ms 47744 KB Output is correct
11 Correct 46 ms 47360 KB Output is correct
12 Correct 42 ms 47352 KB Output is correct
13 Correct 41 ms 47416 KB Output is correct
14 Correct 42 ms 47480 KB Output is correct
15 Correct 43 ms 47468 KB Output is correct
16 Correct 41 ms 47452 KB Output is correct
17 Correct 45 ms 47460 KB Output is correct
18 Correct 41 ms 47468 KB Output is correct
19 Correct 43 ms 47340 KB Output is correct
20 Correct 42 ms 47360 KB Output is correct
21 Correct 44 ms 47612 KB Output is correct
22 Correct 45 ms 47680 KB Output is correct
23 Correct 43 ms 47648 KB Output is correct
24 Correct 44 ms 47568 KB Output is correct
25 Correct 43 ms 47612 KB Output is correct
26 Correct 43 ms 47612 KB Output is correct
27 Correct 43 ms 47608 KB Output is correct
28 Correct 43 ms 47736 KB Output is correct
29 Correct 43 ms 47608 KB Output is correct
30 Correct 42 ms 47608 KB Output is correct
31 Correct 44 ms 47608 KB Output is correct
32 Correct 45 ms 47608 KB Output is correct
33 Correct 916 ms 80468 KB Output is correct
34 Correct 921 ms 80524 KB Output is correct
35 Correct 914 ms 80464 KB Output is correct
36 Correct 937 ms 80504 KB Output is correct
37 Correct 903 ms 80464 KB Output is correct
38 Correct 904 ms 80464 KB Output is correct
39 Correct 925 ms 80480 KB Output is correct
40 Correct 917 ms 80592 KB Output is correct
41 Correct 910 ms 80484 KB Output is correct
42 Correct 903 ms 80608 KB Output is correct
43 Correct 928 ms 80480 KB Output is correct
44 Correct 954 ms 80480 KB Output is correct
45 Correct 932 ms 80492 KB Output is correct
46 Correct 945 ms 80476 KB Output is correct
47 Correct 932 ms 80464 KB Output is correct
48 Correct 942 ms 80484 KB Output is correct
49 Correct 946 ms 80480 KB Output is correct
50 Correct 934 ms 80480 KB Output is correct
51 Correct 942 ms 80464 KB Output is correct
52 Correct 927 ms 80496 KB Output is correct
53 Correct 922 ms 80484 KB Output is correct
54 Correct 938 ms 80652 KB Output is correct
55 Correct 962 ms 80696 KB Output is correct
56 Correct 974 ms 80508 KB Output is correct
57 Correct 965 ms 80624 KB Output is correct
58 Correct 905 ms 80480 KB Output is correct
59 Correct 911 ms 80480 KB Output is correct
60 Correct 909 ms 80456 KB Output is correct
61 Correct 960 ms 80480 KB Output is correct
62 Correct 965 ms 80492 KB Output is correct
63 Correct 946 ms 80480 KB Output is correct
64 Correct 935 ms 80456 KB Output is correct
65 Correct 914 ms 80420 KB Output is correct
66 Correct 928 ms 80464 KB Output is correct
67 Correct 973 ms 80432 KB Output is correct
68 Correct 944 ms 80480 KB Output is correct
69 Correct 925 ms 80468 KB Output is correct
70 Correct 899 ms 80456 KB Output is correct
71 Correct 908 ms 80400 KB Output is correct
72 Correct 907 ms 80480 KB Output is correct
73 Correct 915 ms 80480 KB Output is correct
74 Correct 896 ms 80464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 47608 KB Output is correct
2 Correct 42 ms 47708 KB Output is correct
3 Correct 43 ms 47624 KB Output is correct
4 Correct 45 ms 47608 KB Output is correct
5 Correct 44 ms 47736 KB Output is correct
6 Correct 47 ms 47708 KB Output is correct
7 Correct 45 ms 47712 KB Output is correct
8 Correct 44 ms 47720 KB Output is correct
9 Correct 47 ms 47708 KB Output is correct
10 Correct 44 ms 47608 KB Output is correct
11 Correct 48 ms 47452 KB Output is correct
12 Correct 44 ms 47352 KB Output is correct
13 Correct 43 ms 47464 KB Output is correct
14 Correct 44 ms 47352 KB Output is correct
15 Correct 43 ms 47352 KB Output is correct
16 Correct 47 ms 47612 KB Output is correct
17 Correct 44 ms 47616 KB Output is correct
18 Correct 44 ms 47608 KB Output is correct
19 Correct 46 ms 47608 KB Output is correct
20 Correct 47 ms 47608 KB Output is correct
21 Correct 46 ms 47608 KB Output is correct
22 Correct 46 ms 47612 KB Output is correct
23 Correct 45 ms 47608 KB Output is correct
24 Correct 45 ms 47580 KB Output is correct
25 Correct 45 ms 47744 KB Output is correct
26 Correct 46 ms 47360 KB Output is correct
27 Correct 42 ms 47352 KB Output is correct
28 Correct 41 ms 47416 KB Output is correct
29 Correct 42 ms 47480 KB Output is correct
30 Correct 43 ms 47468 KB Output is correct
31 Correct 41 ms 47452 KB Output is correct
32 Correct 45 ms 47460 KB Output is correct
33 Correct 41 ms 47468 KB Output is correct
34 Correct 43 ms 47340 KB Output is correct
35 Correct 42 ms 47360 KB Output is correct
36 Correct 44 ms 47612 KB Output is correct
37 Correct 45 ms 47680 KB Output is correct
38 Correct 43 ms 47648 KB Output is correct
39 Correct 44 ms 47568 KB Output is correct
40 Correct 43 ms 47612 KB Output is correct
41 Correct 43 ms 47612 KB Output is correct
42 Correct 43 ms 47608 KB Output is correct
43 Correct 43 ms 47736 KB Output is correct
44 Correct 43 ms 47608 KB Output is correct
45 Correct 42 ms 47608 KB Output is correct
46 Correct 44 ms 47608 KB Output is correct
47 Correct 45 ms 47608 KB Output is correct
48 Correct 916 ms 80468 KB Output is correct
49 Correct 921 ms 80524 KB Output is correct
50 Correct 914 ms 80464 KB Output is correct
51 Correct 937 ms 80504 KB Output is correct
52 Correct 903 ms 80464 KB Output is correct
53 Correct 904 ms 80464 KB Output is correct
54 Correct 925 ms 80480 KB Output is correct
55 Correct 917 ms 80592 KB Output is correct
56 Correct 910 ms 80484 KB Output is correct
57 Correct 903 ms 80608 KB Output is correct
58 Correct 928 ms 80480 KB Output is correct
59 Correct 954 ms 80480 KB Output is correct
60 Correct 932 ms 80492 KB Output is correct
61 Correct 945 ms 80476 KB Output is correct
62 Correct 932 ms 80464 KB Output is correct
63 Correct 942 ms 80484 KB Output is correct
64 Correct 946 ms 80480 KB Output is correct
65 Correct 934 ms 80480 KB Output is correct
66 Correct 942 ms 80464 KB Output is correct
67 Correct 927 ms 80496 KB Output is correct
68 Correct 922 ms 80484 KB Output is correct
69 Correct 938 ms 80652 KB Output is correct
70 Correct 962 ms 80696 KB Output is correct
71 Correct 974 ms 80508 KB Output is correct
72 Correct 965 ms 80624 KB Output is correct
73 Correct 905 ms 80480 KB Output is correct
74 Correct 911 ms 80480 KB Output is correct
75 Correct 909 ms 80456 KB Output is correct
76 Correct 960 ms 80480 KB Output is correct
77 Correct 965 ms 80492 KB Output is correct
78 Correct 946 ms 80480 KB Output is correct
79 Correct 935 ms 80456 KB Output is correct
80 Correct 914 ms 80420 KB Output is correct
81 Correct 928 ms 80464 KB Output is correct
82 Correct 973 ms 80432 KB Output is correct
83 Correct 944 ms 80480 KB Output is correct
84 Correct 925 ms 80468 KB Output is correct
85 Correct 899 ms 80456 KB Output is correct
86 Correct 908 ms 80400 KB Output is correct
87 Correct 907 ms 80480 KB Output is correct
88 Correct 915 ms 80480 KB Output is correct
89 Correct 896 ms 80464 KB Output is correct
90 Correct 918 ms 80464 KB Output is correct
91 Correct 906 ms 80520 KB Output is correct
92 Correct 900 ms 80468 KB Output is correct
93 Correct 923 ms 80480 KB Output is correct
94 Correct 911 ms 80464 KB Output is correct
95 Correct 912 ms 80500 KB Output is correct
96 Correct 923 ms 80452 KB Output is correct
97 Correct 933 ms 80456 KB Output is correct
98 Correct 892 ms 80464 KB Output is correct
99 Correct 902 ms 80464 KB Output is correct
100 Correct 665 ms 100268 KB Output is correct
101 Correct 658 ms 100232 KB Output is correct
102 Correct 649 ms 100352 KB Output is correct
103 Correct 672 ms 100324 KB Output is correct
104 Correct 672 ms 100228 KB Output is correct
105 Correct 753 ms 97708 KB Output is correct
106 Correct 743 ms 97668 KB Output is correct
107 Correct 753 ms 97708 KB Output is correct
108 Correct 747 ms 97704 KB Output is correct
109 Correct 762 ms 97732 KB Output is correct
110 Correct 925 ms 80612 KB Output is correct
111 Correct 913 ms 80480 KB Output is correct
112 Correct 955 ms 80480 KB Output is correct
113 Correct 899 ms 80464 KB Output is correct
114 Correct 900 ms 80480 KB Output is correct
115 Correct 933 ms 80480 KB Output is correct
116 Correct 901 ms 80480 KB Output is correct
117 Correct 911 ms 80592 KB Output is correct
118 Correct 887 ms 80536 KB Output is correct
119 Correct 918 ms 80492 KB Output is correct
120 Correct 51 ms 47480 KB Output is correct
121 Correct 45 ms 47484 KB Output is correct
122 Correct 924 ms 80464 KB Output is correct
123 Correct 943 ms 80464 KB Output is correct
124 Correct 978 ms 80592 KB Output is correct
125 Correct 907 ms 80480 KB Output is correct
126 Correct 925 ms 80464 KB Output is correct
127 Correct 912 ms 80480 KB Output is correct
128 Correct 910 ms 80480 KB Output is correct
129 Correct 915 ms 80480 KB Output is correct
130 Correct 924 ms 80464 KB Output is correct
131 Correct 913 ms 80464 KB Output is correct
132 Correct 918 ms 80532 KB Output is correct
133 Correct 898 ms 80464 KB Output is correct