Submission #955900

# Submission time Handle Problem Language Result Execution time Memory
955900 2024-03-31T16:30:52 Z chrisvilches Dragon 2 (JOI17_dragon2) C++14
100 / 100
2140 ms 4180 KB
#include <bits/stdc++.h>
using namespace std;

struct point {
  long long x, y;

  point() : x(0), y(0) {}

  point(long long _x, long long _y) : x(_x), y(_y) {}

  point &operator+=(const point &rhs) {
    x += rhs.x;
    y += rhs.y;
    return *this;
  }

  point &operator-=(const point &rhs) {
    x -= rhs.x;
    y -= rhs.y;
    return *this;
  }
};

point make_point(long long x, long long y) { return point(x, y); }

point operator+(point lhs, const point &rhs) { return lhs += rhs; }

point operator-(point lhs, const point &rhs) { return lhs -= rhs; }

int operator^(const point &lhs, const point &rhs) {
  return lhs.x * rhs.y - lhs.y * rhs.x;
}

bool ccw(const point &a, const point &b, const point &c) {
  // return ((c - a) ^ (b - a)) < 0;
  return (c.x - a.x) * (b.y - a.y) < (c.y - a.y) * (b.x - a.x);
}

bool ccw(const point &b, const point &c) { return ccw(point(), b, c); }

bool cpt(const point &a, const point &b, const point &c) {
  if (ccw(b, c))
    return ccw(b, a) && ccw(a, c);
  else
    return ccw(a, b) && ccw(c, a);
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<point>> cat(M);
  for (int i = 0; i < N; i++) {
    long long x, y;
    int c;
    cin >> x >> y >> c;
    cat[c - 1].emplace_back(x, y);
  }

  long long sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  point S(sx, sy), T(tx, ty);

  int Q;
  cin >> Q;
  while (Q--) {
    int c1, c2;
    cin >> c1 >> c2;
    c1--, c2--;
    long long ans = 0;
    for (const point &p : cat[c1])
      for (const point &q : cat[c2]) ans += int(cpt(q - p, S - p, T - p));
    cout << ans << '\n';
  }
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 348 KB Output is correct
2 Correct 15 ms 516 KB Output is correct
3 Correct 28 ms 348 KB Output is correct
4 Correct 155 ms 584 KB Output is correct
5 Correct 152 ms 632 KB Output is correct
6 Correct 5 ms 600 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 7 ms 600 KB Output is correct
9 Correct 7 ms 348 KB Output is correct
10 Correct 5 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 819 ms 1024 KB Output is correct
2 Correct 1536 ms 1116 KB Output is correct
3 Correct 55 ms 1360 KB Output is correct
4 Correct 24 ms 1104 KB Output is correct
5 Correct 27 ms 1744 KB Output is correct
6 Correct 829 ms 1108 KB Output is correct
7 Correct 804 ms 1232 KB Output is correct
8 Correct 328 ms 1108 KB Output is correct
9 Correct 319 ms 1024 KB Output is correct
10 Correct 302 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 348 KB Output is correct
2 Correct 15 ms 516 KB Output is correct
3 Correct 28 ms 348 KB Output is correct
4 Correct 155 ms 584 KB Output is correct
5 Correct 152 ms 632 KB Output is correct
6 Correct 5 ms 600 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 7 ms 600 KB Output is correct
9 Correct 7 ms 348 KB Output is correct
10 Correct 5 ms 456 KB Output is correct
11 Correct 819 ms 1024 KB Output is correct
12 Correct 1536 ms 1116 KB Output is correct
13 Correct 55 ms 1360 KB Output is correct
14 Correct 24 ms 1104 KB Output is correct
15 Correct 27 ms 1744 KB Output is correct
16 Correct 829 ms 1108 KB Output is correct
17 Correct 804 ms 1232 KB Output is correct
18 Correct 328 ms 1108 KB Output is correct
19 Correct 319 ms 1024 KB Output is correct
20 Correct 302 ms 1016 KB Output is correct
21 Correct 810 ms 1336 KB Output is correct
22 Correct 1547 ms 1104 KB Output is correct
23 Correct 1653 ms 1368 KB Output is correct
24 Correct 593 ms 1620 KB Output is correct
25 Correct 182 ms 1616 KB Output is correct
26 Correct 181 ms 2128 KB Output is correct
27 Correct 49 ms 1884 KB Output is correct
28 Correct 58 ms 1872 KB Output is correct
29 Correct 2140 ms 2512 KB Output is correct
30 Correct 213 ms 3536 KB Output is correct
31 Correct 178 ms 3796 KB Output is correct
32 Correct 193 ms 3700 KB Output is correct
33 Correct 538 ms 3812 KB Output is correct
34 Correct 179 ms 4180 KB Output is correct
35 Correct 179 ms 3796 KB Output is correct
36 Correct 177 ms 3804 KB Output is correct
37 Correct 180 ms 3852 KB Output is correct
38 Correct 772 ms 3700 KB Output is correct
39 Correct 678 ms 3668 KB Output is correct
40 Correct 568 ms 3772 KB Output is correct
41 Correct 1958 ms 3748 KB Output is correct
42 Correct 1366 ms 3756 KB Output is correct
43 Correct 1072 ms 3692 KB Output is correct
44 Correct 1381 ms 2304 KB Output is correct
45 Correct 634 ms 2256 KB Output is correct
46 Correct 409 ms 2668 KB Output is correct
47 Correct 882 ms 2544 KB Output is correct
48 Correct 570 ms 2760 KB Output is correct
49 Correct 340 ms 2412 KB Output is correct