Submission #894234

# Submission time Handle Problem Language Result Execution time Memory
894234 2023-12-28T03:01:35 Z box Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
36 ms 5464 KB
#include "bits/stdc++.h"
using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
 
#define ar array
#define all(v) begin(v), end(v)
#define sz(v) static_cast<int>(v.size())
typedef vector<int> vi;
typedef long long ll;
 
struct Point {
  ll x, y;
  bool operator<(const Point& p) const {
    return x < p.x || (x == p.x && y < p.y);
  }
  bool operator==(const Point& p) const { return (x == p.x && y == p.y); }
  Point operator-(const Point& p) const { return {x - p.x, y - p.y}; }
  friend ll abs(const Point& a) { return a.x * a.x + a.y * a.y; }
  friend ll cross(const Point& a, const Point& b) {
    return a.x * b.y - a.y * b.x;
  }
  friend ll cross(const Point& p, const Point& a, const Point& b) {
    return cross(a - p, b - p);
  }
};
 
vector<Point> getHull(vi a) {
  vector<Point> p;
  F0R(i, sz(a)) {
    Point now = {i, a[i]};
    while (sz(p) > 1 && cross(p[sz(p) - 2], now, p[sz(p) - 1]) >= 0)
      p.pop_back();
    p.push_back(now);
  }
  return p;
}
 
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin.exceptions(cin.failbit);
  int n, m;
  cin >> n >> m;
  vi a(n), b(m);
  F0R(i, n) cin >> a[i];
  F0R(j, m) cin >> b[j];
  auto pa = getHull(a), pb = getHull(b);
  int i = 0, j = 0;
  ll ans = 0;
  while (i + 1 < sz(pa) || j + 1 < sz(pb)) {
    bool c;
    if (i + 1 == sz(pa))
      c = 0;
    else if (j + 1 == sz(pb))
      c = 1;
    else
      c = (pa[i + 1].y - pa[i].y) * (pb[j + 1].x - pb[j].x) <=
          (pb[j + 1].y - pb[j].y) * (pa[i + 1].x - pa[i].x);
    if (c)
      ans += (pa[i + 1].x - pa[i].x) * pb[j].y, i++;
    else
      ans += (pb[j + 1].x - pb[j].x) * pa[i].y, j++;
  }
  cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 480 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 488 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 488 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 488 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 6 ms 1368 KB Output is correct
5 Correct 5 ms 1116 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 13 ms 2396 KB Output is correct
8 Correct 13 ms 2392 KB Output is correct
9 Correct 20 ms 2400 KB Output is correct
10 Correct 13 ms 2388 KB Output is correct
11 Correct 14 ms 2328 KB Output is correct
12 Correct 18 ms 2392 KB Output is correct
13 Correct 13 ms 2380 KB Output is correct
14 Correct 18 ms 2392 KB Output is correct
15 Correct 13 ms 2612 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 480 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 488 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 488 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 488 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 456 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 6 ms 1368 KB Output is correct
33 Correct 5 ms 1116 KB Output is correct
34 Correct 2 ms 720 KB Output is correct
35 Correct 13 ms 2396 KB Output is correct
36 Correct 13 ms 2392 KB Output is correct
37 Correct 20 ms 2400 KB Output is correct
38 Correct 13 ms 2388 KB Output is correct
39 Correct 14 ms 2328 KB Output is correct
40 Correct 18 ms 2392 KB Output is correct
41 Correct 13 ms 2380 KB Output is correct
42 Correct 18 ms 2392 KB Output is correct
43 Correct 13 ms 2612 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 460 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 604 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 9 ms 1884 KB Output is correct
56 Correct 0 ms 516 KB Output is correct
57 Correct 2 ms 604 KB Output is correct
58 Correct 3 ms 732 KB Output is correct
59 Correct 18 ms 3536 KB Output is correct
60 Correct 19 ms 3528 KB Output is correct
61 Correct 18 ms 3540 KB Output is correct
62 Correct 36 ms 3532 KB Output is correct
63 Correct 19 ms 5464 KB Output is correct
64 Correct 19 ms 3540 KB Output is correct
65 Correct 21 ms 3556 KB Output is correct
66 Correct 28 ms 3524 KB Output is correct
67 Correct 19 ms 3776 KB Output is correct