Submission #716091

# Submission time Handle Problem Language Result Execution time Memory
716091 2023-03-29T02:00:27 Z Ozy Dragon 2 (JOI17_dragon2) C++17
100 / 100
2822 ms 3936 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 14 ms 340 KB Output is correct
2 Correct 19 ms 436 KB Output is correct
3 Correct 33 ms 504 KB Output is correct
4 Correct 185 ms 1356 KB Output is correct
5 Correct 195 ms 1604 KB Output is correct
6 Correct 6 ms 468 KB Output is correct
7 Correct 6 ms 492 KB Output is correct
8 Correct 7 ms 340 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 7 ms 372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 894 ms 1596 KB Output is correct
2 Correct 1571 ms 1648 KB Output is correct
3 Correct 67 ms 1904 KB Output is correct
4 Correct 36 ms 1840 KB Output is correct
5 Correct 37 ms 2484 KB Output is correct
6 Correct 875 ms 1664 KB Output is correct
7 Correct 852 ms 1664 KB Output is correct
8 Correct 375 ms 1656 KB Output is correct
9 Correct 351 ms 1396 KB Output is correct
10 Correct 372 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 340 KB Output is correct
2 Correct 19 ms 436 KB Output is correct
3 Correct 33 ms 504 KB Output is correct
4 Correct 185 ms 1356 KB Output is correct
5 Correct 195 ms 1604 KB Output is correct
6 Correct 6 ms 468 KB Output is correct
7 Correct 6 ms 492 KB Output is correct
8 Correct 7 ms 340 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 7 ms 372 KB Output is correct
11 Correct 894 ms 1596 KB Output is correct
12 Correct 1571 ms 1648 KB Output is correct
13 Correct 67 ms 1904 KB Output is correct
14 Correct 36 ms 1840 KB Output is correct
15 Correct 37 ms 2484 KB Output is correct
16 Correct 875 ms 1664 KB Output is correct
17 Correct 852 ms 1664 KB Output is correct
18 Correct 375 ms 1656 KB Output is correct
19 Correct 351 ms 1396 KB Output is correct
20 Correct 372 ms 1388 KB Output is correct
21 Correct 864 ms 1736 KB Output is correct
22 Correct 1564 ms 1764 KB Output is correct
23 Correct 1736 ms 2100 KB Output is correct
24 Correct 688 ms 3168 KB Output is correct
25 Correct 212 ms 3196 KB Output is correct
26 Correct 211 ms 3856 KB Output is correct
27 Correct 69 ms 2896 KB Output is correct
28 Correct 61 ms 2836 KB Output is correct
29 Correct 2822 ms 3692 KB Output is correct
30 Correct 233 ms 3464 KB Output is correct
31 Correct 252 ms 3800 KB Output is correct
32 Correct 233 ms 3696 KB Output is correct
33 Correct 611 ms 3636 KB Output is correct
34 Correct 230 ms 3884 KB Output is correct
35 Correct 210 ms 3668 KB Output is correct
36 Correct 235 ms 3584 KB Output is correct
37 Correct 213 ms 3868 KB Output is correct
38 Correct 936 ms 3936 KB Output is correct
39 Correct 779 ms 3736 KB Output is correct
40 Correct 658 ms 3732 KB Output is correct
41 Correct 2487 ms 3784 KB Output is correct
42 Correct 1586 ms 3620 KB Output is correct
43 Correct 1194 ms 3624 KB Output is correct
44 Correct 1767 ms 2304 KB Output is correct
45 Correct 873 ms 2312 KB Output is correct
46 Correct 562 ms 2332 KB Output is correct
47 Correct 968 ms 2288 KB Output is correct
48 Correct 637 ms 2136 KB Output is correct
49 Correct 373 ms 2288 KB Output is correct