답안 #551731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551731 2022-04-21T11:47:46 Z cadmiumsky Bulldozer (JOI17_bulldozer) C++14
25 / 100
2000 ms 764 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
using ll = long long;
const int nmax = 2e3 + 5;
int n;

namespace SSM {
  //#define int ll
  struct Node {
    int sum, pref, suff, mx;
    Node() : sum(0), pref(0), suff(0), mx(0) {;}
    Node(int val) : sum(val), pref(max(0LL, val)), suff(max(0LL, val)), mx(max(0LL, val)) {;}
    Node(int s, int p, int u, int m) : sum(s), pref(p), suff(u), mx(m) {;}
    Node operator +(const Node& x) const {
      return Node(x.sum + sum, 
                  max(pref, sum + x.pref), 
                  max(x.suff, x.sum + suff), 
                  max({mx, x.mx, suff + x.pref}));
    }
  };
  //#undef int
  Node aint[nmax * 4];
  void upd(int poz, ll val, int node = 1, int cl = 0, int cr = n - 1) {
    if(cl == cr) {
      aint[node] = Node(val);
      return;
    }
    int mid = cl + cr >> 1;
    if(poz <= mid)
      upd(poz, val, 2 * node, cl, mid);
    else
      upd(poz, val, 2 * node + 1, mid + 1, cr);
    aint[node] = aint[2 * node] + aint[2 * node + 1];
  }
  ll query() { return aint[1].mx; }
};

vector< tuple<int,int,int> > points;
vector<int> ind;

namespace LineContainer { // catthink
  pair<int,int> getline(int l, int r) { return {-(get<1>(points[l]) - get<1>(points[r])), -(get<0>(points[l]) - get<0>(points[r]))};}; 
  auto cmpline = [](pair<int,int> l, pair<int,int> r) { 
    if(l.second == 0 && r.second == 0)
      return false;
    if(l.second == 0)
      return true;
    if(r.second == 0)
      return false;
    if(!((((ll)l.first * l.second) >= 0) ^ ((((ll)r.first * r.second) >= 0))))
      return (ll)l.first * r.second > (ll)r.first * l.second;
    return l.first * l.second >= 0;
  };
  auto eqline = [](pair<int,int> l, pair<int,int> r) { return !cmpline(l, r) && !cmpline(r, l); };
  auto eq = [](int i, int j) { return eqline(getline(ind[i], ind[i + 1]), getline(ind[j], ind[j + 1])); };
  auto cmp = [](int i, int j) { return cmpline(getline(ind[i], ind[i + 1]), getline(ind[j], ind[j + 1]))
                                        || (eq(i, j) && i < j); };
  set<int, decltype(cmp)> heap(cmp);
  void rev(int l, int r) {
    if(l > 0 && ind[l - 1] < ind[l])
      heap.erase(l - 1);
    if(r < ind.size() - 1 && ind[r] < ind[r + 1])
      heap.erase(r);
    reverse(ind.begin() + l, ind.begin() + r + 1);
    if(l > 0 && ind[l - 1] < ind[l])
      heap.insert(l - 1);
    if(r < ind.size() - 1 && ind[r] < ind[r + 1])
      heap.insert(r);
    for(int i = l; i <= r; i++) {
      SSM::upd(i, get<2>(points[ind[i]]));
    }    
  }
  int startmove() {
    if(heap.size() == 0)
      return -1;
    int u = *heap.begin(), last = u;
    //cerr << "- " << u << '\n';
    heap.erase(heap.begin());
    while(!heap.empty() && eq(*heap.begin(), u)) {
      if(*heap.begin() - u > 1) {
        rev(last, u + 1);
        last = *heap.begin();
      }
      u = *heap.begin();
      heap.erase(heap.begin());
    }
    rev(last, u + 1);
    return SSM::query();
  }
}

signed main() {
  cin >> n;
  points.resize(n);
  ind.resize(n);
  for(auto &[a, b, c] : points)
    cin >> a >> b >> c;
  sort(points.begin(), points.end());
  for(int i = 0; i < n; i++)
    //cerr << get<0>(points[i]) << ' ' << get<1>(points[i]) << '\n', 
    SSM::upd(i, get<2>(points[i])),
    ind[i] = i;
  for(int i = 0; i < n - 1; i++)
    LineContainer::heap.insert(i);
  int mx = SSM::query(), temp;
  while((temp = LineContainer::startmove()) >= 0) {
    //cerr << temp << '\n';
    mx = max(mx, temp);
  }
  //for(int i = 0; i < n; i++)
    //assert(ind[i] == n - i - 1);
  cout << mx << '\n';
}

Compilation message

bulldozer.cpp: In function 'void SSM::upd(long long int, ll, long long int, long long int, long long int)':
bulldozer.cpp:29:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
bulldozer.cpp: In function 'void LineContainer::rev(long long int, long long int)':
bulldozer.cpp:63:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     if(r < ind.size() - 1 && ind[r] < ind[r + 1])
      |        ~~^~~~~~~~~~~~~~~~
bulldozer.cpp:68:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     if(r < ind.size() - 1 && ind[r] < ind[r + 1])
      |        ~~^~~~~~~~~~~~~~~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:97:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   97 |   for(auto &[a, b, c] : points)
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 560 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 468 KB Output is correct
2 Correct 5 ms 468 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 5 ms 468 KB Output is correct
8 Correct 5 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 552 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 556 KB Output is correct
19 Correct 1 ms 552 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 4 ms 556 KB Output is correct
23 Correct 5 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 4 ms 560 KB Output is correct
29 Correct 5 ms 468 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 4 ms 552 KB Output is correct
32 Correct 4 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 468 KB Output is correct
2 Correct 5 ms 468 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 5 ms 468 KB Output is correct
8 Correct 5 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 552 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 556 KB Output is correct
19 Correct 1 ms 552 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 4 ms 556 KB Output is correct
23 Correct 5 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 4 ms 560 KB Output is correct
29 Correct 5 ms 468 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 4 ms 552 KB Output is correct
32 Correct 4 ms 468 KB Output is correct
33 Correct 1811 ms 748 KB Output is correct
34 Correct 1894 ms 700 KB Output is correct
35 Correct 1826 ms 764 KB Output is correct
36 Correct 1808 ms 752 KB Output is correct
37 Correct 1772 ms 756 KB Output is correct
38 Correct 1814 ms 756 KB Output is correct
39 Correct 1775 ms 756 KB Output is correct
40 Correct 1779 ms 724 KB Output is correct
41 Correct 1827 ms 760 KB Output is correct
42 Correct 1802 ms 760 KB Output is correct
43 Correct 1804 ms 760 KB Output is correct
44 Correct 1757 ms 756 KB Output is correct
45 Correct 1738 ms 756 KB Output is correct
46 Correct 1754 ms 748 KB Output is correct
47 Correct 1749 ms 756 KB Output is correct
48 Correct 1812 ms 752 KB Output is correct
49 Execution timed out 2009 ms 756 KB Time limit exceeded
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 468 KB Output is correct
2 Correct 5 ms 468 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 5 ms 468 KB Output is correct
8 Correct 5 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 552 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 556 KB Output is correct
19 Correct 1 ms 552 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 4 ms 556 KB Output is correct
23 Correct 5 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 4 ms 560 KB Output is correct
29 Correct 5 ms 468 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 4 ms 552 KB Output is correct
32 Correct 4 ms 468 KB Output is correct
33 Correct 1811 ms 748 KB Output is correct
34 Correct 1894 ms 700 KB Output is correct
35 Correct 1826 ms 764 KB Output is correct
36 Correct 1808 ms 752 KB Output is correct
37 Correct 1772 ms 756 KB Output is correct
38 Correct 1814 ms 756 KB Output is correct
39 Correct 1775 ms 756 KB Output is correct
40 Correct 1779 ms 724 KB Output is correct
41 Correct 1827 ms 760 KB Output is correct
42 Correct 1802 ms 760 KB Output is correct
43 Correct 1804 ms 760 KB Output is correct
44 Correct 1757 ms 756 KB Output is correct
45 Correct 1738 ms 756 KB Output is correct
46 Correct 1754 ms 748 KB Output is correct
47 Correct 1749 ms 756 KB Output is correct
48 Correct 1812 ms 752 KB Output is correct
49 Execution timed out 2009 ms 756 KB Time limit exceeded
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 560 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 4 ms 468 KB Output is correct
20 Correct 4 ms 468 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 5 ms 468 KB Output is correct
23 Correct 5 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 552 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 556 KB Output is correct
34 Correct 1 ms 552 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 4 ms 468 KB Output is correct
37 Correct 4 ms 556 KB Output is correct
38 Correct 5 ms 468 KB Output is correct
39 Correct 4 ms 468 KB Output is correct
40 Correct 4 ms 468 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 4 ms 468 KB Output is correct
43 Correct 4 ms 560 KB Output is correct
44 Correct 5 ms 468 KB Output is correct
45 Correct 3 ms 468 KB Output is correct
46 Correct 4 ms 552 KB Output is correct
47 Correct 4 ms 468 KB Output is correct
48 Correct 1811 ms 748 KB Output is correct
49 Correct 1894 ms 700 KB Output is correct
50 Correct 1826 ms 764 KB Output is correct
51 Correct 1808 ms 752 KB Output is correct
52 Correct 1772 ms 756 KB Output is correct
53 Correct 1814 ms 756 KB Output is correct
54 Correct 1775 ms 756 KB Output is correct
55 Correct 1779 ms 724 KB Output is correct
56 Correct 1827 ms 760 KB Output is correct
57 Correct 1802 ms 760 KB Output is correct
58 Correct 1804 ms 760 KB Output is correct
59 Correct 1757 ms 756 KB Output is correct
60 Correct 1738 ms 756 KB Output is correct
61 Correct 1754 ms 748 KB Output is correct
62 Correct 1749 ms 756 KB Output is correct
63 Correct 1812 ms 752 KB Output is correct
64 Execution timed out 2009 ms 756 KB Time limit exceeded
65 Halted 0 ms 0 KB -